cubetools / react-settle-promise
settle function for react-promise
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 4 534
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 6
Forks: 0
Open Issues: 1
Requires
- php: >=5.4.0
- react/promise: ^2.1.0|^1.2.0
Requires (Dev)
- react/promise-timer: ^1.0.0
Suggests
- react/promise-timer: for settleWithTimeout()
This package is auto-updated.
Last update: 2022-02-09 18:34:42 UTC
README
Settle function for React\Promise.
Usage
use CubeTools\React\SettlePromise; $promises = [ React\Promise\resolve('foo'), React\Promise\reject(new \Exception()), 'bar' ]; SettlePromise\settle($promises)->then(function(array $states) { foreach($states as $state) { if (SettlePromise\FULFILLED === $state['state']) { $promiseValue = $state['value']; ... } else { // SettlePromise\REJECTED $failureReason = $state['reason']; ... } } });
use CubeTools\React\SettlePromise; use Clue\React\Block; $loop = \React\EventLoop\Factory::create(); foreach(Block\await(SettlePromise\settleWithTimeout($promises, 5, $loop), $loop) { if (SettlePromise\FULFILLED === $state['state']) { $promiseValue = $state['value']; ... } else { // SettlePromise\REJECTED $failureReason = $state['reason']; ... } }
To replace the constants, subclass \CubeTools\React\SettlePromise\SettlePromise and define the class constants FULFILLED and REJECTED.
Then use the class functions like YourClass::settle(...)
.
Installation
Step 1: Download the Package
Open a command console, enter your project directory and execute the following command to download the latest stable version of this package:
$ composer require cubetools/react-settle-promise
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.