Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Utils.php

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

Utils

Namespace

GuzzleHttp\Promise

Code

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal