function Promise::then
Same name in this branch
- 11.1.x vendor/php-http/guzzle7-adapter/src/Promise.php \Http\Adapter\Guzzle7\Promise::then()
- 11.1.x vendor/php-http/promise/src/Promise.php \Http\Promise\Promise::then()
- 11.1.x vendor/guzzlehttp/promises/src/Promise.php \GuzzleHttp\Promise\Promise::then()
Overrides PromiseInterface::then
2 calls to Promise::then()
- Promise::catch in vendor/
react/ promise/ src/ Promise.php - @template TThrowable of \Throwable @template TRejected
- Promise::finally in vendor/
react/ promise/ src/ Promise.php - Allows you to execute "cleanup" type tasks in a promise chain.
File
-
vendor/
react/ promise/ src/ Promise.php, line 44
Class
- Promise
- @template T @template-implements PromiseInterface<T>
Namespace
React\PromiseCode
public function then(?callable $onFulfilled = null, ?callable $onRejected = null) : PromiseInterface {
if (null !== $this->result) {
return $this->result
->then($onFulfilled, $onRejected);
}
if (null === $this->canceller) {
return new static($this->resolver($onFulfilled, $onRejected));
}
// This promise has a canceller, so we create a new child promise which
// has a canceller that invokes the parent canceller if all other
// followers are also cancelled. We keep a reference to this promise
// instance for the static canceller function and clear this to avoid
// keeping a cyclic reference between parent and follower.
$parent = $this;
++$parent->requiredCancelRequests;
return new static($this->resolver($onFulfilled, $onRejected), static function () use (&$parent) : void {
assert($parent instanceof self);
--$parent->requiredCancelRequests;
if ($parent->requiredCancelRequests <= 0) {
$parent->cancel();
}
$parent = null;
});
}