SDK for PHP V3

PromiseInterface
in

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.

Tags
template

TValue = mixed

template

TReason = mixed

see
https://promisesaplus.com/

Table of Contents

Constants

FULFILLED  = 'fulfilled'
PENDING  = 'pending'
REJECTED  = 'rejected'

Methods

cancel()  : void
Cancels the promise if possible.
getState()  : self::PENDING|self::FULFILLED|self::REJECTED
Get the state of the promise ("pending", "rejected", or "fulfilled").
otherwise()  : PromiseInterface<TValue|TRejectedValue, TRejectedReason|Throwable>
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.
reject()  : void
Reject the promise with the given reason.
resolve()  : void
Resolve the promise with the given value, or with null if no value is given.
then()  : PromiseInterface<mixed, mixed>
Appends fulfillment and rejection handlers to the promise, and returns a new promise resolving to the return value of the called handler.
wait()  : mixed
Waits until the promise completes if possible.

Constants

FULFILLED

public mixed FULFILLED = 'fulfilled'

PENDING

public mixed PENDING = 'pending'

REJECTED

public mixed REJECTED = 'rejected'

Methods

getState()

Get the state of the promise ("pending", "rejected", or "fulfilled").

public getState() : self::PENDING|self::FULFILLED|self::REJECTED

The three states can be checked against the constants defined on PromiseInterface: PENDING, FULFILLED, and REJECTED.

Return values
self::PENDING|self::FULFILLED|self::REJECTED

otherwise()

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.

public otherwise(callable $onRejected) : PromiseInterface<TValue|TRejectedValue, TRejectedReason|Throwable>
Parameters
$onRejected : callable
Tags
template

TRejectedValue = never

template

TRejectedReason = never

Return values
PromiseInterface<TValue|TRejectedValue, TRejectedReason|Throwable>

reject()

Reject the promise with the given reason.

public reject(TReason $reason) : void
Parameters
$reason : TReason
Tags
throws
RuntimeException

if the promise is already resolved.

resolve()

Resolve the promise with the given value, or with null if no value is given.

public resolve([TValue|PromiseInterface<TValue, TReason>|null $value = null ]) : void
Parameters
$value : TValue|PromiseInterface<TValue, TReason>|null = null
Tags
throws
RuntimeException

if the promise is already resolved.

then()

Appends fulfillment and rejection handlers to the promise, and returns a new promise resolving to the return value of the called handler.

public then([ Warning: Array to string conversion in phar:///codebuild/output/src2989036412/src/aws-sdk-php/build/artifacts/phpDocumentor.phar/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 78 callable(TValue): Array|null $onFulfilled = null ][, Warning: Array to string conversion in phar:///codebuild/output/src2989036412/src/aws-sdk-php/build/artifacts/phpDocumentor.phar/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 78 callable(TReason): Array|null $onRejected = null ]) : PromiseInterface<mixed, mixed>
Parameters
$onFulfilled : Warning: Array to string conversion in phar:///codebuild/output/src2989036412/src/aws-sdk-php/build/artifacts/phpDocumentor.phar/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 78 callable(TValue): Array|null = null

Invoked when the promise fulfills.

$onRejected : Warning: Array to string conversion in phar:///codebuild/output/src2989036412/src/aws-sdk-php/build/artifacts/phpDocumentor.phar/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 78 callable(TReason): Array|null = null

Invoked when the promise is rejected.

Tags
template

TFulfilledValue = never

template

TFulfilledReason = never

template

TRejectedValue = never

template

TRejectedReason = never

Return values
PromiseInterface<mixed, mixed>

wait()

Waits until the promise completes if possible.

public wait([bool $unwrap = true ]) : mixed

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
$unwrap : bool = true
Tags
throws
LogicException

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

<-- modeled_exceptions -->
On this page