function task in Lockr 7.3
Adds a function to run in the task queue when it is next `run()` and returns a promise that is fulfilled or rejected with the result.
Parameters
callable $task Task function to run.:
Return value
File
- vendor/
guzzlehttp/ promises/ src/ functions.php, line 42
Namespace
GuzzleHttp\PromiseCode
function task(callable $task) {
$queue = queue();
$promise = new Promise([
$queue,
'run',
]);
$queue
->add(function () use ($task, $promise) {
try {
$promise
->resolve($task());
} catch (\Throwable $e) {
$promise
->reject($e);
} catch (\Exception $e) {
$promise
->reject($e);
}
});
return $promise;
}