esroyo / react-promise-settle
Returns a promise that is fulfilled when all of the provided promises have been fulfilled or rejected.
Requires
- php: >=5.4.0
- react/promise: ^2.7.1
Requires (Dev)
- phpunit/phpunit: ^7.1 || ^6.4
This package is auto-updated.
Last update: 2024-10-27 00:56:45 UTC
README
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.