You are here

function task in Auth0 Single Sign On 8.2

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

PromiseInterface

File

vendor/guzzlehttp/promises/src/functions.php, line 42

Namespace

GuzzleHttp\Promise

Code

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;
}