Documentation

Promise
in package

FinalYes
Tags
psalm-type

PromiseMapCallback = callable(mixed $value): mixed

psalm-type

PromiseReduceCallback = callable(mixed $value): mixed

Table of Contents

Methods

all()  : PromiseInterface
Returns a promise that resolves when all items in `$promises` have resolved.
any()  : PromiseInterface
Returns a promise that resolves when any item in `$promises` resolves.
map()  : PromiseInterface
Applies a callback function to each item in `$promises`.
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.
reduce()  : PromiseInterface
Applies a callback function to each item in `$promises`, reducing them to a single value.
reject()  : PromiseInterface<string|int, never>
Creates a rejected promise for the supplied `$promiseOrValue`.
resolve()  : PromiseInterface
Creates a fulfilled promise for the supplied `$promiseOrValue`.
some()  : PromiseInterface
Returns a promise that resolves when `$count` items in `$promises` resolve.

Methods

all()

Returns a promise that resolves when all items in `$promises` have resolved.

public static all(iterable<int, PromiseInterface|mixed> $promises) : PromiseInterface

The returned promise's resolution value will be an array containing the resolution values of each item in $promises.

Parameters
$promises : iterable<int, PromiseInterface|mixed>
Return values
PromiseInterface

any()

Returns a promise that resolves when any item in `$promises` resolves.

public static any(iterable<int, PromiseInterface|mixed> $promises) : PromiseInterface

The returned promise's resolution value will be the resolution value of the triggering item. If all items in $promises are rejected, the returned promise will reject with an array of all rejection reasons.

If $promises is empty, the returned promise will reject with a LengthException.

Parameters
$promises : iterable<int, PromiseInterface|mixed>
Return values
PromiseInterface

map()

Applies a callback function to each item in `$promises`.

public static map(iterable<int, PromiseInterface|mixed> $promises, callable $map) : PromiseInterface

This function behaves like array_map(), but it can handle input containing promises and/or values, and the $callback may return either a value or a promise.

The $callback function receives each item as an argument, where the item is a fully resolved value of a promise or a value in $promises.

Parameters
$promises : iterable<int, PromiseInterface|mixed>
$map : callable
Tags
psalm-param

PromiseMapCallback $map

Return values
PromiseInterface

race()

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

public static 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>

reduce()

Applies a callback function to each item in `$promises`, reducing them to a single value.

public static reduce(iterable<int, PromiseInterface|mixed> $promises, callable(mixed $current, mixed $carry, int $current, positive-int $items): mixed $reduce[, mixed $initial = null ]) : PromiseInterface

This function behaves like array_reduce(), but it can handle input containing promises and/or values. The $reduce callback may return either a value or a promise, and $initial may be a promise or a value for the starting value.

Parameters
$promises : iterable<int, PromiseInterface|mixed>
$reduce : callable(mixed $current, mixed $carry, int $current, positive-int $items): mixed
$initial : mixed = null
Tags
psalm-param

PromiseReduceCallback $reduce

Return values
PromiseInterface

reject()

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

public static reject([mixed $promiseOrValue = null ]) : PromiseInterface<string|int, never>

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

If $promiseOrValue 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
$promiseOrValue : mixed = null
Return values
PromiseInterface<string|int, never>

resolve()

Creates a fulfilled promise for the supplied `$promiseOrValue`.

public static resolve([mixed $promiseOrValue = null ]) : PromiseInterface

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 : mixed = null
Return values
PromiseInterface

some()

Returns a promise that resolves when `$count` items in `$promises` resolve.

public static some(iterable<int, PromiseInterface|mixed> $promises, int $count) : PromiseInterface

The returned promise's resolution value will be an array of length $count containing the resolution values of the triggering items.

If it becomes impossible for $count items to resolve (i.e., when (count($promises) - $count) + 1 items reject), the returned promise will reject with an iterable exception of (count($promises) - $howMany) + 1 rejection reasons.

If $promises contains fewer items than $count, the returned promise will reject with a LengthException.

Parameters
$promises : iterable<int, PromiseInterface|mixed>
$count : int
Return values
PromiseInterface

        
On this page

Search results