Download the PHP package skelan/simple-promise without Composer
On this page you can find all versions of the php package skelan/simple-promise. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package simple-promise
Promise
A lightweight implementation of CommonJS Promises/A for PHP.
This file mostly code come from react/promise, thanks reactphp Team provide such a useful package.
Installation
Make sure that you have composer installed Composer.
If you don't have Composer run the below command
Run the installation
Concepts
Deferred
A Deferred represents a computation or unit of work that may not have completed yet. Typically (but not always), that computation will be something that executes asynchronously and completes at some point in the future.
Promise
While a deferred represents the computation itself, a Promise represents the result of that computation. Thus, each deferred has a promise that acts as a placeholder for its actual result.
API
Deferred
A deferred represents an operation whose resolution is pending. It has separate promise and resolver parts.
How promise forwarding works
A few simple examples to show how the mechanics of Promises/A forwarding works. These examples are contrived, of course, and in real usage, promise chains will typically be spread across several function calls, or even several levels of your application architecture.
Resolution forwarding
Resolved promises forward resolution values to the next promise.
The first promise, $deferred->promise()
, will resolve with the value passed
to $deferred->resolve()
below.
Each call to then()
returns a new promise that will resolve with the return
value of the previous handler. This creates a promise "pipeline".
Rejection forwarding
Rejected promises behave similarly, and also work similarly to try/catch: When you catch an exception, you must rethrow for it to propagate.
Similarly, when you handle a rejected promise, to propagate the rejection, "rethrow" it by either returning a rejected promise, or actually throwing (since promise translates thrown exceptions into rejections)
Best practices
1) Try/catch demo
Just like try/catch, you can choose to propagate or not. Mixing resolutions and rejections will still forward handler results in a predictable way.
2) Asynchronous call
swoole is awesome extension of php
License
Released under the MIT license.