vendor/ezimuel/ringphp/src/Future/CompletedFutureValue.php line 65

Open in your IDE?
  1. <?php
  2. namespace GuzzleHttp\Ring\Future;
  3. use React\Promise\FulfilledPromise;
  4. use React\Promise\RejectedPromise;
  5. use React\Promise\PromiseInterface;
  6. /**
  7.  * Represents a future value that has been resolved or rejected.
  8.  */
  9. class CompletedFutureValue implements FutureInterface
  10. {
  11.     protected $result;
  12.     protected $error;
  13.     private $cachedPromise;
  14.     /**
  15.      * @param mixed      $result Resolved result
  16.      * @param \Exception $e      Error. Pass a GuzzleHttp\Ring\Exception\CancelledFutureAccessException
  17.      *                           to mark the future as cancelled.
  18.      */
  19.     public function __construct($result, \Exception $e null)
  20.     {
  21.         $this->result $result;
  22.         $this->error $e;
  23.     }
  24.     /**
  25.      * @return mixed
  26.      */
  27.     public function wait()
  28.     {
  29.         if ($this->error) {
  30.             throw $this->error;
  31.         }
  32.         return $this->result;
  33.     }
  34.     public function cancel() {}
  35.     /**
  36.      * @return PromiseInterface
  37.      */
  38.     public function promise()
  39.     {
  40.         if (!$this->cachedPromise) {
  41.             $this->cachedPromise $this->error
  42.                 ? new RejectedPromise($this->error)
  43.                 : new FulfilledPromise($this->result);
  44.         }
  45.         return $this->cachedPromise;
  46.     }
  47.     /**
  48.      * @return PromiseInterface
  49.      */
  50.     public function then(
  51.         callable $onFulfilled null,
  52.         callable $onRejected null,
  53.         callable $onProgress null
  54.     ) {
  55.         return $this->promise()->then($onFulfilled$onRejected$onProgress);
  56.     }
  57. }