FulfilledPromise
in package
implements
Promise
A promise already fulfilled.
Tags
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
- $result : mixed
Methods
- __construct() : mixed
- getState() : string
- Returns the state of the promise, one of PENDING, FULFILLED or REJECTED.
- 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
$result
private
mixed
$result
Methods
__construct()
public
__construct(mixed $result) : mixed
Parameters
- $result : mixed
getState()
Returns the state of the promise, one of PENDING, FULFILLED or REJECTED.
public
getState() : string
Return values
stringthen()
Adds behavior for when the promise is resolved or rejected (response will be available, or error happens).
public
then([callable|null $onFulfilled = null ][, callable|null $onRejected = null ]) : Promise
If you do not care about one of the cases, you can set the corresponding callable to null The callback will be called when the value arrived and never more than once.
Parameters
- $onFulfilled : callable|null = null
-
called when a response will be available
- $onRejected : callable|null = 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
When this method returns, the request has been resolved and if callables have been specified, the appropriate one has terminated.
When $unwrap is true (the default), the response is returned, or the exception thrown on failure. Otherwise, nothing is returned or thrown.
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