You are here

function promise_for in Lockr 7.3

Creates a promise for a value if the value is not a promise.

Parameters

mixed $value Promise or value.:

Return value

PromiseInterface

2 calls to promise_for()
EachPromise::addPending in vendor/guzzlehttp/promises/src/EachPromise.php
Promise::then in vendor/guzzlehttp/promises/src/Promise.php
Appends fulfillment and rejection handlers to the promise, and returns a new promise resolving to the return value of the called handler.

File

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

Namespace

GuzzleHttp\Promise

Code

function promise_for($value) {
  if ($value instanceof PromiseInterface) {
    return $value;
  }

  // Return a Guzzle promise that shadows the given promise.
  if (method_exists($value, 'then')) {
    $wfn = method_exists($value, 'wait') ? [
      $value,
      'wait',
    ] : null;
    $cfn = method_exists($value, 'cancel') ? [
      $value,
      'cancel',
    ] : null;
    $promise = new Promise($wfn, $cfn);
    $value
      ->then([
      $promise,
      'resolve',
    ], [
      $promise,
      'reject',
    ]);
    return $promise;
  }
  return new FulfilledPromise($value);
}