Kraken\Promise\Promise::then PHP Method

then() public method

public then ( callable $onFulfilled = null, callable $onRejected = null, callable $onCancel = null )
$onFulfilled callable
$onRejected callable
$onCancel callable
    public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onCancel = null)
    {
        if (null !== $this->result) {
            return $this->getResult()->then($onFulfilled, $onRejected, $onCancel);
        }
        if (null !== $this->canceller) {
            $this->requiredCancellations++;
            $canceller = function ($reason = null) {
                if (++$this->currentCancellations >= $this->requiredCancellations) {
                    return $this->cancel($reason);
                }
                return null;
            };
        } else {
            $canceller = null;
        }
        return new static(function ($resolve, $reject, $cancel) use($onFulfilled, $onRejected, $onCancel) {
            $this->handlers[] = function (PromiseInterface $promise) use($resolve, $reject, $cancel, $onFulfilled, $onRejected, $onCancel) {
                $promise->then($onFulfilled, $onRejected, $onCancel)->done($resolve, $reject, $cancel);
            };
        }, $canceller);
    }

Usage Example

Example #1
0
 /**
  *
  */
 public function testCasePromise_RejectsPromise_IfResolverThrowsException()
 {
     $exception = new Exception('foo');
     $promise = new Promise(function () use($exception) {
         throw $exception;
     });
     $mock = $this->createCallableMock();
     $mock->expects($this->once())->method('__invoke')->with($this->identicalTo($exception));
     $promise->then($this->expectCallableNever(), $mock);
 }
All Usage Examples Of Kraken\Promise\Promise::then