Deferred
in package
implements
Promise
FinalYes
A deferred allow to return a promise which has not been resolved yet.
Table of Contents
Interfaces
- Promise
- Promise represents a value that may not be available yet, but will be resolved at some point in future.
Properties
- $failure : ClientExceptionInterface|null
- $onFulfilledCallbacks : array<string|int, callable>
- $onRejectedCallbacks : array<string|int, callable>
- $state : string
- $value : ResponseInterface|null
- $waitCallback : callable
Methods
- __construct() : mixed
- getState() : string
- Returns the state of the promise, one of PENDING, FULFILLED or REJECTED.
- reject() : void
- Reject this deferred with an Exception.
- resolve() : void
- Resolve this deferred with a Response.
- then() : Promise
- Adds behavior for when the promise is resolved or rejected (response will be available, or error happens).
- wait() : mixed
- Wait for the promise to be fulfilled or rejected.
Properties
$failure
private
ClientExceptionInterface|null
$failure
$onFulfilledCallbacks
private
array<string|int, callable>
$onFulfilledCallbacks
$onRejectedCallbacks
private
array<string|int, callable>
$onRejectedCallbacks
$state
private
string
$state
$value
private
ResponseInterface|null
$value
$waitCallback
private
callable
$waitCallback
Methods
__construct()
public
__construct(callable $waitCallback) : mixed
Parameters
- $waitCallback : callable
getState()
Returns the state of the promise, one of PENDING, FULFILLED or REJECTED.
public
getState() : string
Return values
stringreject()
Reject this deferred with an Exception.
public
reject(ClientExceptionInterface $exception) : void
Parameters
- $exception : ClientExceptionInterface
resolve()
Resolve this deferred with a Response.
public
resolve(ResponseInterface $response) : void
Parameters
- $response : ResponseInterface
then()
Adds behavior for when the promise is resolved or rejected (response will be available, or error happens).
public
then([callable $onFulfilled = null ][, callable $onRejected = null ]) : Promise
Parameters
- $onFulfilled : callable = null
-
called when a response will be available
- $onRejected : callable = null
-
called when an exception occurs
Return values
Promise —a new resolved promise with value of the executed callback (onFulfilled / onRejected)
wait()
Wait for the promise to be fulfilled or rejected.
public
wait([mixed $unwrap = true ]) : mixed
Parameters
- $unwrap : mixed = true
-
Whether to return resolved value / throw reason or not
Return values
mixed —Resolved value, null if $unwrap is set to false