\GuzzleHttp\PromisePromiseInterface

A promise represents the eventual result of an asynchronous operation.

The primary way of interacting with a promise is through its then method, which registers callbacks to receive either a promise’s eventual value or the reason why the promise cannot be fulfilled.

Summary

Methods
Constants
then()
otherwise()
getState()
resolve()
reject()
cancel()
wait()
PENDING
FULFILLED
REJECTED
No protected methods found
N/A
No private methods found
N/A

Constants

PENDING

PENDING = 'pending'

FULFILLED

FULFILLED = 'fulfilled'

REJECTED

REJECTED = 'rejected'

Methods

then()

then(callable  $onFulfilled = null, callable  $onRejected = null) : \GuzzleHttp\Promise\PromiseInterface

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

Invoked when the promise fulfills.

callable $onRejected

Invoked when the promise is rejected.

Returns

\GuzzleHttp\Promise\PromiseInterface —

otherwise()

otherwise(callable  $onRejected) : \GuzzleHttp\Promise\PromiseInterface

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 —

getState()

getState() : string

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 —

resolve()

resolve(mixed  $value) : mixed

Resolve the promise with the given value.

Parameters

mixed $value

Throws

\RuntimeException

if the promise is already resolved.

Returns

mixed —

reject()

reject(mixed  $reason) : mixed

Reject the promise with the given reason.

Parameters

mixed $reason

Throws

\RuntimeException

if the promise is already resolved.

Returns

mixed —

cancel()

cancel() : mixed

Cancels the promise if possible.

Returns

mixed —

wait()

wait(bool  $unwrap = true) : mixed

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

bool $unwrap

Throws

\LogicException

if the promise has no wait function or if the promise does not settle after waiting.

Returns

mixed —