Promise
in
Promise represents a value that may not be available yet, but will be resolved at some point in future.
It acts like a proxy to the actual value.
This interface is an extension of the promises/a+ specification.
Tags
Table of Contents
Constants
- FULFILLED = 'fulfilled'
- Promise has been fulfilled.
- PENDING = 'pending'
- Promise has not been fulfilled or rejected.
- REJECTED = 'rejected'
- Promise has been rejected.
Methods
- 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.
Constants
FULFILLED
Promise has been fulfilled.
public
mixed
FULFILLED
= 'fulfilled'
PENDING
Promise has not been fulfilled or rejected.
public
mixed
PENDING
= 'pending'
REJECTED
Promise has been rejected.
public
mixed
REJECTED
= 'rejected'
Methods
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([bool $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 : bool = true
-
Whether to return resolved value / throw reason or not
Tags
Return values
mixed —Resolved value, null if $unwrap is set to false