Download the PHP package onion/promise without Composer
On this page you can find all versions of the php package onion/promise. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package promise
Introduction
This is an Promises/A+ implementation that should be fully compatible with any already existing implementations without any 3rd party dependencies.
This package defines 2 interfaces PromiseInterface
& ThenableInterface
as per the spec also there are some helper functions as well as some that provide a more
sugary feel to the code.
is_thenable
- Function that checks if an object is "thenable"
coroutine
- Push a task as a promise. This one changes it's implementation depending on whether or not the swoole
extension is
available on the server. If it is then the native coroutines available as go
function are used, alternatively it falls back to an approach similar to an event loop.
A tick function is registered using register_tick_function
that will invoke 1 task per so that not to bring your application to a complete halt when executing. As well as there is a function registered for shutdown that will run all remaining tasks in a blocking way until the queue is empty - albeit hanging the request.
For when the synchronous mode is used, you should do declare(ticks=1)
see the PHP Docs
NOTE: Please, keep in mind that your code will block until the task is processed so this 'mode' is not recommended and users should look at alternative approaches for their heavy tasks or install swoole
async
- alias for coroutine
, intended to mimic the async
keyword in JS/TS/C#
==============
Usage
The function passed to async
/coroutine
will be executed immediately so do keep in mind that
when using without swoole
.