GuzzleHttpPromisepromise_for

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

Description

GuzzleHttp\Promise\promise_for( (mixed) $value ); 

Parameters (1)

0. $value (mixed)
Promise or value.

Usage

  1. if ( !function_exists( 'GuzzleHttp\Promise\promise_for' ) ) { 
  2. require_once '/lib/Azure/GuzzleHttp/Promise/functions.php'; 
  3.  
  4. // Promise or value. 
  5. $value = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = GuzzleHttp\Promise\promise_for($value); 
  9.  

Defined (1)

The function is defined in the following location(s).

/lib/Azure/GuzzleHttp/Promise/functions.php  
  1. function promise_for($value) 
  2. if ($value instanceof PromiseInterface) { 
  3. return $value; 
  4.  
  5. // Return a Guzzle promise that shadows the given promise. 
  6. if (method_exists($value, 'then')) { 
  7. $wfn = method_exists($value, 'wait') ? [$value, 'wait'] : null; 
  8. $cfn = method_exists($value, 'cancel') ? [$value, 'cancel'] : null; 
  9. $promise = new Promise($wfn, $cfn); 
  10. $value->then([$promise, 'resolve'], [$promise, 'reject']); 
  11. return $promise; 
  12.  
  13. return new FulfilledPromise($value);