Documentation

functions.php

Table of Contents

Functions

resolve()  : PromiseInterface<string|int, T>
Creates a promise for the supplied `$promiseOrValue`.
reject()  : PromiseInterface<string|int, never>
Creates a rejected promise for the supplied `$reason`.
all()  : PromiseInterface<string|int, array<string|int, T>>
Returns a promise that will resolve only once all the items in `$promisesOrValues` have resolved. The resolution value of the returned promise will be an array containing the resolution values of each of the items in `$promisesOrValues`.
race()  : PromiseInterface<string|int, T>
Initiates a competitive race that allows one winner. Returns a promise which is resolved in the same way the first settled promise resolves.
any()  : PromiseInterface<string|int, T>
Returns a promise that will resolve when any one of the items in `$promisesOrValues` resolves. The resolution value of the returned promise will be the resolution value of the triggering item.
set_rejection_handler()  : callable(Throwable): void|null
Sets the global rejection handler for unhandled promise rejections.

Functions

resolve()

Creates a promise for the supplied `$promiseOrValue`.

resolve(PromiseInterface<string|int, T>|T $promiseOrValue) : PromiseInterface<string|int, T>

If $promiseOrValue is a value, it will be the resolution value of the returned promise.

If $promiseOrValue is a thenable (any object that provides a then() method), a trusted promise that follows the state of the thenable is returned.

If $promiseOrValue is a promise, it will be returned as is.

Parameters
$promiseOrValue : PromiseInterface<string|int, T>|T
Tags
template

T

Return values
PromiseInterface<string|int, T>

reject()

Creates a rejected promise for the supplied `$reason`.

reject(Throwable $reason) : PromiseInterface<string|int, never>

If $reason is a value, it will be the rejection value of the returned promise.

If $reason is a promise, its completion value will be the rejected value of the returned promise.

This can be useful in situations where you need to reject a promise without throwing an exception. For example, it allows you to propagate a rejection with the value of another promise.

Parameters
$reason : Throwable
Return values
PromiseInterface<string|int, never>

all()

Returns a promise that will resolve only once all the items in `$promisesOrValues` have resolved. The resolution value of the returned promise will be an array containing the resolution values of each of the items in `$promisesOrValues`.

all(iterable<string|int, PromiseInterface<string|int, T>|T$promisesOrValues) : PromiseInterface<string|int, array<string|int, T>>
Parameters
$promisesOrValues : iterable<string|int, PromiseInterface<string|int, T>|T>
Tags
template

T

Return values
PromiseInterface<string|int, array<string|int, T>>

race()

Initiates a competitive race that allows one winner. Returns a promise which is resolved in the same way the first settled promise resolves.

race(iterable<string|int, PromiseInterface<string|int, T>|T$promisesOrValues) : PromiseInterface<string|int, T>

The returned promise will become infinitely pending if $promisesOrValues contains 0 items.

Parameters
$promisesOrValues : iterable<string|int, PromiseInterface<string|int, T>|T>
Tags
template

T

Return values
PromiseInterface<string|int, T>

any()

Returns a promise that will resolve when any one of the items in `$promisesOrValues` resolves. The resolution value of the returned promise will be the resolution value of the triggering item.

any(iterable<string|int, PromiseInterface<string|int, T>|T$promisesOrValues) : PromiseInterface<string|int, T>

The returned promise will only reject if all items in $promisesOrValues are rejected. The rejection value will be an array of all rejection reasons.

The returned promise will also reject with a React\Promise\Exception\LengthException if $promisesOrValues contains 0 items.

Parameters
$promisesOrValues : iterable<string|int, PromiseInterface<string|int, T>|T>
Tags
template

T

Return values
PromiseInterface<string|int, T>

set_rejection_handler()

Sets the global rejection handler for unhandled promise rejections.

set_rejection_handler(callable(Throwable): void|null $callback) : callable(Throwable): void|null

Note that rejected promises should always be handled similar to how any exceptions should always be caught in a try + catch block. If you remove the last reference to a rejected promise that has not been handled, it will report an unhandled promise rejection. See also the reject() function for more details.

The ?callable $callback argument MUST be a valid callback function that accepts a single Throwable argument or a null value to restore the default promise rejection handler. The return value of the callback function will be ignored and has no effect, so you SHOULD return a void value. The callback function MUST NOT throw or the program will be terminated with a fatal error.

The function returns the previous rejection handler or null if using the default promise rejection handler.

The default promise rejection handler will log an error message plus its stack trace:

// Unhandled promise rejection with RuntimeException: Unhandled in example.php:2
React\Promise\reject(new RuntimeException('Unhandled'));

The promise rejection handler may be used to use customize the log message or write to custom log targets. As a rule of thumb, this function should only be used as a last resort and promise rejections are best handled with either the then() method, the catch() method, or the finally() method. See also the reject() function for more details.

Parameters
$callback : callable(Throwable): void|null
Return values
callable(Throwable): void|null

        
On this page

Search results