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

Breadcrumb

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

function Promise::callHandler

Call a stack of handlers using a specific callback index and value.

Parameters

int $index 1 (resolve) or 2 (reject).:

mixed $value Value to pass to the callback.:

array $handler Array of handler data (promise and callbacks).:

1 call to Promise::callHandler()
Promise::settle in vendor/guzzlehttp/promises/src/Promise.php

File

vendor/guzzlehttp/promises/src/Promise.php, line 188

Class

Promise
Promises/A+ implementation that avoids recursion when possible.

Namespace

GuzzleHttp\Promise

Code

private static function callHandler(int $index, $value, array $handler) : void {
    
    /** @var PromiseInterface $promise */
    $promise = $handler[0];
    // The promise may have been cancelled or resolved before placing
    // this thunk in the queue.
    if (Is::settled($promise)) {
        return;
    }
    try {
        if (isset($handler[$index])) {
            
            /*
             * If $f throws an exception, then $handler will be in the exception
             * stack trace. Since $handler contains a reference to the callable
             * itself we get a circular reference. We clear the $handler
             * here to avoid that memory leak.
             */
            $f = $handler[$index];
            unset($handler);
            $promise->resolve($f($value));
        }
        elseif ($index === 1) {
            // Forward resolution values as-is.
            $promise->resolve($value);
        }
        else {
            // Forward rejections down the chain.
            $promise->reject($value);
        }
    } catch (\Throwable $reason) {
        $promise->reject($reason);
    }
}

API Navigation

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