Download the PHP package react/promise-timer without Composer

On this page you can find all versions of the php package react/promise-timer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package promise-timer

PromiseTimer

CI status installs on Packagist

A trivial implementation of timeouts for Promises, built on top of ReactPHP.

Table of contents

Usage

This lightweight library consists only of a few simple functions. All functions reside under the React\Promise\Timer namespace.

The below examples refer to all functions with their fully-qualified names like this:

As of PHP 5.6+ you can also import each required function into your code like this:

Alternatively, you can also use an import statement similar to this:

timeout()

The timeout(PromiseInterface<T> $promise, float $time, ?LoopInterface $loop = null): PromiseInterface<T> function can be used to cancel operations that take too long.

You need to pass in an input $promise that represents a pending operation and timeout parameters. It returns a new promise with the following resolution behavior:

Internally, the given $time value will be used to start a timer that will cancel the pending operation once it triggers. This implies that if you pass a really small (or negative) value, it will still start a timer and will thus trigger at the earliest possible time in the future.

If the input $promise is already settled, then the resulting promise will resolve or reject immediately without starting a timer at all.

This function takes an optional LoopInterface|null $loop parameter that can be used to pass the event loop instance to use. You can use a null value here in order to use the default loop. This value SHOULD NOT be given unless you're sure you want to explicitly use a given event loop instance.

A common use case for handling only resolved values looks like this:

A more complete example could look like this:

Or if you're using react/promise v3:

As discussed above, the timeout() function will take care of the underlying operation if it takes too long. In this case, you can be sure the resulting promise will always be rejected with a TimeoutException. On top of this, the function will try to cancel the underlying operation. Responsibility for this cancellation logic is left up to the underlying operation.

On top of this, the returned promise is implemented in such a way that it can be cancelled when it is still pending. Cancelling a pending promise will cancel the underlying operation. As discussed above, responsibility for this cancellation logic is left up to the underlying operation.

For more details on the promise cancellation, please refer to the Promise documentation.

If you want to wait for multiple promises to resolve, you can use the normal promise primitives like this:

The applies to all promise collection primitives alike, i.e. all(), race(), any(), some() etc.

For more details on the promise primitives, please refer to the Promise documentation.

sleep()

The sleep(float $time, ?LoopInterface $loop = null): PromiseInterface<void> function can be used to create a new promise that resolves in $time seconds.

Internally, the given $time value will be used to start a timer that will resolve the promise once it triggers. This implies that if you pass a really small (or negative) value, it will still start a timer and will thus trigger at the earliest possible time in the future.

This function takes an optional LoopInterface|null $loop parameter that can be used to pass the event loop instance to use. You can use a null value here in order to use the default loop. This value SHOULD NOT be given unless you're sure you want to explicitly use a given event loop instance.

The returned promise is implemented in such a way that it can be cancelled when it is still pending. Cancelling a pending promise will reject its value with a RuntimeException and clean up any pending timers.

resolve()

Deprecated since v1.8.0, see sleep() instead.

The resolve(float $time, ?LoopInterface $loop = null): PromiseInterface<float> function can be used to create a new promise that resolves in $time seconds with the $time as the fulfillment value.

Internally, the given $time value will be used to start a timer that will resolve the promise once it triggers. This implies that if you pass a really small (or negative) value, it will still start a timer and will thus trigger at the earliest possible time in the future.

This function takes an optional LoopInterface|null $loop parameter that can be used to pass the event loop instance to use. You can use a null value here in order to use the default loop. This value SHOULD NOT be given unless you're sure you want to explicitly use a given event loop instance.

The returned promise is implemented in such a way that it can be cancelled when it is still pending. Cancelling a pending promise will reject its value with a RuntimeException and clean up any pending timers.

reject()

Deprecated since v1.8.0, see sleep() instead.

The reject(float $time, ?LoopInterface $loop = null): PromiseInterface<never> function can be used to create a new promise which rejects in $time seconds with a TimeoutException.

Internally, the given $time value will be used to start a timer that will reject the promise once it triggers. This implies that if you pass a really small (or negative) value, it will still start a timer and will thus trigger at the earliest possible time in the future.

This function takes an optional LoopInterface|null $loop parameter that can be used to pass the event loop instance to use. You can use a null value here in order to use the default loop. This value SHOULD NOT be given unless you're sure you want to explicitly use a given event loop instance.

The returned promise is implemented in such a way that it can be cancelled when it is still pending. Cancelling a pending promise will reject its value with a RuntimeException and clean up any pending timers.

TimeoutException

The TimeoutException extends PHP's built-in RuntimeException.

getTimeout()

The getTimeout(): float method can be used to get the timeout value in seconds.

Install

The recommended way to install this library is through Composer. New to Composer?

This project follows SemVer. This will install the latest supported version:

See also the CHANGELOG for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.3 through current PHP 8+ and HHVM. It's highly recommended to use the latest supported PHP version for this project.

Tests

To run the test suite, you first need to clone this repo and then install all dependencies through Composer:

To run the test suite, go to the project root and run:

License

MIT, see LICENSE file.


All versions of promise-timer with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3
react/event-loop Version ^1.2
react/promise Version ^3.2 || ^2.7.0 || ^1.2.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package react/promise-timer contains the following files

Loading the files please wait ....