react/promise-timer
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
react/event-loop | v1.5.0 | 39.55 kB | MIT | prod | |
react/promise | v3.2.0 | - | MIT | prod |
The PHP package react/promise-timer provides a straightforward means to implementing timeouts for Promises, fortified with the power of ReactPHP. This lightweight library meticulously handles operations that take longer than desired. It also gives the functionality to create a new promise that executes in a specified time period. What's more, it presents the utility to automatically cancel pending operations experiencing delays, effectively ensuring efficient and smooth functioning of your applications.
Having Composer installed, you can use the react/promise-timer package by installing it with the following command:
composer require react/promise-timer:^1.10
As per the PHP version you're running, this will install the latest supported version of react/promise-timer.
The library provides different timing functions and cancellation methods. Here are some examples on how to usage it:
use function React\Promise\Timer\timeout;
$promise = someFuncReturningPromise();
timeout($promise, 10.0)->then(function ($value) {
// the operation finished in less than 10.0 seconds
});
use React\Promise\Timer;
$promise = someFuncReturningPromise();
Timer\timeout($promise, 10.0)->then(
function ($value) {
// the operation finished in less than 10.0 seconds
},
function ($error) {
if ($error instanceof React\Promise\Timer\TimeoutException) {
// the operation has failed due to a timeout
} else {
// the operation has failed due to some other error
}
}
);
You can also toggle the optional cancellation feature of the promise:
$promise = someFuncReturningPromise();
$timeout = Timer\timeout($promise, 10.0);
$timeout->cancel();
The react/promise-timer documentation is hosted directly within the GitHub repository. All you need to know about its functionality and implementation is clearly elaborated in the ReadMe file of the official react/promise-timer GitHub repository. Navigate through the content to find specific instructions on usage, installation, tests execution, function descriptions along with code examples.