Class Promise
- GuzzleHttp\Promise\Promise implements GuzzleHttp\Promise\PromiseInterface
- Namespace: GuzzleHttp\Promise
- Link: https://promisesaplus.com/
- Located at Promise.php
Promises/A+ implementation that avoids recursion when possible.
Methods Summary
- __construct ( callable $waitFn = null, callable $cancelFn = null )
-
then ( callable $onFulfilled = null, callable $onRejected = null )
Appends fulfillment and rejection handlers to the promise, and returns a new promise resolving to the return value of the called handler.
-
otherwise ( callable $onRejected )
Appends a rejection handler callback to the promise, and returns a new promise resolving to the return value of the callback if it is called, or to its original fulfillment value if the promise is instead fulfilled.
-
wait ( bool $unwrap = true )
Waits until the promise completes if possible.
-
getState ( )
Get the state of the promise ("pending", "rejected", or "fulfilled").
-
cancel ( )
Cancels the promise if possible.
-
resolve ( mixed $value )
Resolve the promise with the given value.
-
reject ( mixed $reason )
Reject the promise with the given reason.
Methods Details
__construct ( callable $waitFn = null, callable $cancelFn = null )
Parameters
callable | $waitFn = null | Fn that when invoked resolves the promise. |
callable | $cancelFn = null | Fn that when invoked cancels the promise. |
GuzzleHttp\Promise\PromiseInterface
then (
callable
$onFulfilled = null,
callable
$onRejected = null
)
Appends fulfillment and rejection handlers to the promise, and returns a new promise resolving to the return value of the called handler.
Parameters
callable | $onFulfilled = null | Invoked when the promise fulfills. |
callable | $onRejected = null | Invoked when the promise is rejected. |
Returns
GuzzleHttp\Promise\PromiseInterface |
Implementation of
GuzzleHttp\Promise\PromiseInterface
otherwise (
callable
$onRejected
)
Appends a rejection handler callback to the promise, and returns a new promise resolving to the return value of the callback if it is called, or to its original fulfillment value if the promise is instead fulfilled.
Parameters
callable | $onRejected | Invoked when the promise is rejected. |
Returns
GuzzleHttp\Promise\PromiseInterface |
Implementation of
mixed wait ( boolean $unwrap = true )
Waits until the promise completes if possible.
Pass $unwrap as true to unwrap the result of the promise, either returning the resolved value or throwing the rejected exception.
If the promise cannot be waited on, then the promise will be rejected.
Parameters
boolean | $unwrap = true |
Returns
mixed |
Exceptions
LogicException if the promise has no wait function or if the promise does not settle after waiting. |
Implementation of
string getState ( )
Get the state of the promise ("pending", "rejected", or "fulfilled").
The three states can be checked against the constants defined on PromiseInterface: PENDING, FULFILLED, and REJECTED.
Returns
string |
Implementation of
cancel ( )
Cancels the promise if possible.
Link
Implementation of
resolve ( mixed $value )
Resolve the promise with the given value.
Parameters
mixed | $value |
Exceptions
RuntimeException if the promise is already resolved. |
Implementation of
reject ( mixed $reason )
Reject the promise with the given reason.
Parameters
mixed | $reason |
Exceptions
RuntimeException if the promise is already resolved. |