GuzzleHttpPromiseRejectedPromise

A promise that has been rejected.

Defined (1)

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

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