esroyo/react-promise-settle

Returns a promise that is fulfilled when all of the provided promises have been fulfilled or rejected.

dev-master / 1.0.0.x-dev 2021-11-26 18:19 UTC

This package is auto-updated.

Last update: 2024-10-27 00:56:45 UTC


README

builds.sr.ht status Software License Total Downloads

Provides a settle() function missing from the official react/promise.

Installation

composer require esroyo/react-promise-settle

Usage

$promise = Esroyo\React\Promise\settle(array $promisesOrValues);

Returns a promise that is fullfilled when all the items in $promisesOrValues have been fulfilled or rejected.

The resolution value of the returned promise will be an state associative array containing a "state" key mapping to a valid promise state. If the state of the promise is "fulfilled", the array will contain a "value" key mapping to the fulfilled value of the promise. If the promise is rejected, the array will contain a "reason" key mapping to the rejection reason of the promise.

Example result (array keys should be according to $promisesOrValues input):

[
    ['state' => 'fulfilled', 'value' => 'Result of work'],
    ['state' => 'rejected', 'reason' => 'Timeout'],
    ...
]

Credits

This package is a reaccommodation of cubetools/react-settle-promise and the original idea, authored by @jsor and @SimonHeimberg.