Download the PHP package drewlabs/async without Composer
On this page you can find all versions of the php package drewlabs/async. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download drewlabs/async
More information about drewlabs/async
Files in drewlabs/async
Package async
Short Description Provides utility function for async programming in PHP
License MIT
Informations about the package async
Async
The async
library provides a list of utility functions to doing basic async programming in PHP language. It makes use of PHP Generator
to implement a co-routine platform on top of which async tasks are executed.
Usage
The library provides the following utility functions:
- async
async(callable $waitFn)
The async
utility provides an asynchronous function execution context for the subroutine passed as argument.
It returns a Awaitable
instance which start the subroutine when wait()
is invoked on it. The wait()
statement as it will pause the script execution until the subroutine complete.
-
promise
promise(callable $waitFn, bool $shutdown = false)
promise
provides a factory function that create promise A+ specification instance. It takes a waitable function with a reference to therevolve
function as first param and a reference to thereject
function of the promise instance as second parameter.Note In the above example, without calling
wait()
, the promise coroutine to execute, does not run. To create a promise that automatically run on PHP process shutdown, the factory function takes a second boolean flag as parameter. -
defer
defer(callable $waitFn)
defer
creates a promise instance that executes resolve and reject callbacks when onPHP
process shutdown. It's the simply version ofpromise($waitFn, true)
- join
join(...$waitFn)
join
, is same as async
interface, except the fact that is takes a list of subroutines wait on the result of those subroutines and return the a list of the awaited result in the order they were inserted.
-
await & all
await($coroutine) / all(array $coroutines)
These are utility function for waiting onasync
andjoin
subroutines respectively.all
works the same asawait
except that is takes an array of promises or subroutines and returns an array of resolved values.