/** * @param PromiseInterface|ExtendedPromiseInterface|mixed $promiseOrValue * * @return FulfilledPromise|Promise */ function resolve($promiseOrValue = null) { if (false === $promiseOrValue instanceof PromiseInterface) { return new FulfilledPromise($promiseOrValue); } if ($promiseOrValue instanceof ExtendedPromiseInterface) { return $promiseOrValue; } return new Promise(function ($resolve, $reject, $notify) use($promiseOrValue) { $promiseOrValue->then($resolve, $reject, $notify); }); }
/** * Promise handler * * @param array|PromiseInterface $promise * @param Generator $gen */ private function give($promise, Generator $gen) { if ($promise instanceof PromiseInterface) { $promise->then(function ($result) use($gen) { if ($promise = $gen->send($result)) { $this->give($promise, $gen); } }); } else { all($promise)->then(function ($results) use($gen) { if ($promise = $gen->send($results)) { $this->give($promise, $gen); } }); } $this->client->send(); }
/** * Returns true if a promise is fulfilled or rejected. * * @param PromiseInterface $promise * * @return bool */ function is_settled(PromiseInterface $promise) { return $promise->getState() !== PromiseInterface::PENDING; }
/** * {@inheritdoc} */ public function state() { return $this->actual !== null ? $this->actual->state() : State::PENDING(); }