コード例 #1
0
 /**
  * @param PromiseInterface $promise
  */
 protected function pendingThenTest(PromiseInterface $promise)
 {
     $this->given($onFulfilled = $this->delegateMock(), $onRejected = $this->delegateMock(), $onNotify = $this->delegateMock())->when($promise->then($onFulfilled, $onRejected, $onNotify))->then()->delegateCall($onFulfilled)->never()->delegateCall($onRejected)->never()->delegateCall($onNotify)->never();
 }
コード例 #2
0
ファイル: Promises.php プロジェクト: cubiche/cubiche
 /**
  * @param PromiseInterface $promise
  * @param int|float        $time
  * @param LoopInterface    $loop
  *
  * @return \Cubiche\Core\Async\Promise\PromiseInterface
  */
 public static function timeout(PromiseInterface $promise, $time, LoopInterface $loop)
 {
     $deferred = self::defer();
     $timer = $loop->timeout(function () use($promise, $deferred, $time) {
         $deferred->reject(new TimeoutException($time));
     }, $time);
     $promise->then(function ($value = null) use($deferred, $timer) {
         $timer->cancel();
         $deferred->resolve($value);
     }, function ($reason = null) use($deferred, $timer) {
         $timer->cancel();
         $deferred->reject($reason);
     });
     return $deferred->promise();
 }