示例#1
0
 /**
  * {@inheritdoc}
  */
 public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onNotify = null)
 {
     if ($this->state()->equals(State::PENDING())) {
         $resolver = new ThenResolver($onFulfilled, $onRejected, $onNotify);
         $this->resolvers[] = $resolver;
         return $resolver->promise();
     }
     return $this->actual->then($onFulfilled, $onRejected, $onNotify);
 }
示例#2
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);
    });
}
示例#3
0
文件: Invoker.php 项目: m6w6/seekat
 /**
  * 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();
 }