Пример #1
0
/**
 * @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);
    });
}
Пример #2
0
 /**
  * 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();
 }
Пример #3
0
/**
 * Returns true if a promise is fulfilled or rejected.
 *
 * @param PromiseInterface $promise
 *
 * @return bool
 */
function is_settled(PromiseInterface $promise)
{
    return $promise->getState() !== PromiseInterface::PENDING;
}
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function state()
 {
     return $this->actual !== null ? $this->actual->state() : State::PENDING();
 }