You are here

private static function Promise::callHandler in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/guzzlehttp/promises/src/Promise.php \GuzzleHttp\Promise\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).:

Return value

array Returns the next group to resolve.

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

File

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

Class

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

Namespace

GuzzleHttp\Promise

Code

private static function callHandler($index, $value, array $handler) {

  /** @var PromiseInterface $promise */
  $promise = $handler[0];

  // The promise may have been cancelled or resolved before placing
  // this thunk in the queue.
  if ($promise
    ->getState() !== self::PENDING) {
    return;
  }
  try {
    if (isset($handler[$index])) {
      $promise
        ->resolve($handler[$index]($value));
    }
    elseif ($index === 1) {

      // Forward resolution values as-is.
      $promise
        ->resolve($value);
    }
    else {

      // Forward rejections down the chain.
      $promise
        ->reject($value);
    }
  } catch (\Exception $reason) {
    $promise
      ->reject($reason);
  }
}