GuzzleHttpPromiseFulfilledPromise

A promise that has been fulfilled.

Defined (1)

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

/lib/Azure/GuzzleHttp/Promise/FulfilledPromise.php  
  1. class FulfilledPromise implements PromiseInterface 
  2. private $value; 
  3.  
  4. public function __construct($value) 
  5. if (method_exists($value, 'then')) { 
  6. throw new \InvalidArgumentException( 
  7. 'You cannot create a FulfilledPromise with a promise.'); 
  8.  
  9. $this->value = $value; 
  10.  
  11. public function then( 
  12. callable $onFulfilled = null,  
  13. callable $onRejected = null 
  14. ) { 
  15. // Return itself if there is no onFulfilled function. 
  16. if (!$onFulfilled) { 
  17. return $this; 
  18.  
  19. $queue = queue(); 
  20. $p = new Promise([$queue, 'run']); 
  21. $value = $this->value; 
  22. $queue->add(static function () use ($p, $value, $onFulfilled) { 
  23. if ($p->getState() === self::PENDING) { 
  24. try { 
  25. $p->resolve($onFulfilled($value)); 
  26. } catch (\Throwable $e) { 
  27. $p->reject($e); 
  28. } catch (\Exception $e) { 
  29. $p->reject($e); 
  30. }); 
  31.  
  32. return $p; 
  33.  
  34. public function otherwise(callable $onRejected) 
  35. return $this->then(null, $onRejected); 
  36.  
  37. public function wait($unwrap = true, $defaultDelivery = null) 
  38. return $unwrap ? $this->value : null; 
  39.  
  40. public function getState() 
  41. return self::FULFILLED; 
  42.  
  43. public function resolve($value) 
  44. if ($value !== $this->value) { 
  45. throw new \LogicException("Cannot resolve a fulfilled promise"); 
  46.  
  47. public function reject($reason) 
  48. throw new \LogicException("Cannot reject a fulfilled promise"); 
  49.  
  50. public function cancel() 
  51. // pass