Beispiel #1
0
 /**
  * Resolves the awaitable with the given awaitable or value. If another awaitable, this awaitable takes on the state
  * of that awaitable. If a value, the awaitable will be fulfilled with that value.
  *
  * @param mixed $value An awaitable can be resolved with anything other than itself.
  */
 protected function resolve($value = null)
 {
     if (null !== $this->result) {
         return;
     }
     if ($value instanceof self) {
         $value = $value->unwrap();
         if ($this === $value) {
             $value = new Internal\RejectedAwaitable(new CircularResolutionError('Circular reference in awaitable resolution chain.'));
         }
     } elseif (!$value instanceof Awaitable) {
         $value = new Internal\FulfilledAwaitable($value);
     }
     $this->result = $value;
     $this->result->done($this->onFulfilled, $this->onRejected ?: new DoneQueue());
     $this->onFulfilled = null;
     $this->onRejected = null;
     $this->onCancelled = null;
 }
 /**
  * @param \Icicle\Awaitable\Awaitable $awaitable
  */
 public function __construct(Awaitable $awaitable)
 {
     parent::__construct(function () use($awaitable) {
         return new Promise(function ($resolve, $reject) use($awaitable) {
             $awaitable->done($resolve, $reject);
         }, function () use($awaitable) {
             $awaitable->cancel();
         });
     });
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function done(callable $onFulfilled = null, callable $onRejected = null)
 {
     $this->result->done(null, $onRejected);
 }
 /**
  * {@inheritdoc}
  */
 public function done(callable $onFulfilled = null, callable $onRejected = null)
 {
     $this->awaitable->done($onFulfilled, $onRejected);
 }