/**
  * @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();
         });
     });
 }
Exemple #2
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;
 }
Exemple #3
0
 /**
  * @param \Icicle\Postgres\Connection $connection
  *
  * @throws \Icicle\Exception\InvalidArgumentError
  */
 private function push(Connection $connection)
 {
     if (!isset($this->connections[$connection])) {
         throw new InvalidArgumentError('Connection is not part of this pool');
     }
     $this->idle->push($connection);
     if ($this->awaitable instanceof Delayed) {
         $this->awaitable->resolve($connection);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function wait()
 {
     return $this->result->wait();
 }
 /**
  * {@inheritdoc}
  */
 public function isCancelled() : bool
 {
     return $this->awaitable->isCancelled();
 }