function Utils::task
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.:
File
-
vendor/
guzzlehttp/ promises/ src/ Utils.php, line 43
Class
Namespace
GuzzleHttp\PromiseCode
public static function task(callable $task) : PromiseInterface {
$queue = self::queue();
$promise = new Promise([
$queue,
'run',
]);
$queue->add(function () use ($task, $promise) : void {
try {
if (Is::pending($promise)) {
$promise->resolve($task());
}
} catch (\Throwable $e) {
$promise->reject($e);
}
});
return $promise;
}