AWS SDK for PHP 3.x (original) (raw)

PromiseInterface

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

see

https://promisesaplus.com/

Table of Contents

Constants

FULFILLED = 'fulfilled'

PENDING = 'pending'

REJECTED = 'rejected'

Methods

cancel() : void

Cancels the promise if possible.

getState() : string

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

otherwise() : 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.

reject() : void

Reject the promise with the given reason.

resolve() : void

Resolve the promise with the given value.

then() : PromiseInterface

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.

FULFILLED

public mixed FULFILLED = 'fulfilled'

PENDING

public mixed PENDING = 'pending'

REJECTED

public mixed REJECTED = 'rejected'

cancel()

Cancels the promise if possible.

public cancel() : void

Tags

see

https://github.com/promises-aplus/cancellation-spec/issues/7

getState()

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

public getState() : string

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

Return values

string

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](class-GuzzleHttp.Promise.PromiseInterface.html)

Parameters

$onRejected : callable

Invoked when the promise is rejected.

Return values

PromiseInterface

reject()

Reject the promise with the given reason.

public reject(mixed $reason) : void

Parameters

$reason : mixed

Tags

throws

RuntimeException

if the promise is already resolved.

resolve()

Resolve the promise with the given value.

public resolve(mixed $value) : void

Parameters

$value : mixed

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([callable <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>o</mi><mi>n</mi><mi>F</mi><mi>u</mi><mi>l</mi><mi>f</mi><mi>i</mi><mi>l</mi><mi>l</mi><mi>e</mi><mi>d</mi><mo>=</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo stretchy="false">]</mo><mo stretchy="false">[</mo><mo separator="true">,</mo><mi>c</mi><mi>a</mi><mi>l</mi><mi>l</mi><mi>a</mi><mi>b</mi><mi>l</mi><mi>e</mi></mrow><annotation encoding="application/x-tex">onFulfilled = null ][, callable </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mord mathnormal" style="margin-right:0.13889em;">F</span><span class="mord mathnormal">u</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.01968em;">ll</span><span class="mord mathnormal">e</span><span class="mord mathnormal">d</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">n</span><span class="mord mathnormal">u</span><span class="mord mathnormal" style="margin-right:0.01968em;">ll</span><span class="mclose">]</span><span class="mopen">[</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">c</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.01968em;">ll</span><span class="mord mathnormal">ab</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span></span></span></span>onRejected = null ]) : [PromiseInterface](class-GuzzleHttp.Promise.PromiseInterface.html)

Parameters

$onFulfilled : callable = null

Invoked when the promise fulfills.

$onRejected : callable = null

Invoked when the promise is rejected.

Return values

PromiseInterface

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.