function Promise::then
Same name in this branch
- 11.1.x vendor/react/promise/src/Promise.php \React\Promise\Promise::then()
- 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()
Overrides PromiseInterface::then
1 call to Promise::then()
- Promise::otherwise in vendor/
guzzlehttp/ promises/ src/ Promise.php - Appends a rejection handler callback to the promise, and returns a new promise resolving to the return value of the callback if it is called, or to its original fulfillment value if the promise is instead fulfilled.
File
-
vendor/
guzzlehttp/ promises/ src/ Promise.php, line 35
Class
- Promise
- Promises/A+ implementation that avoids recursion when possible.
Namespace
GuzzleHttp\PromiseCode
public function then(?callable $onFulfilled = null, ?callable $onRejected = null) : PromiseInterface {
if ($this->state === self::PENDING) {
$p = new Promise(null, [
$this,
'cancel',
]);
$this->handlers[] = [
$p,
$onFulfilled,
$onRejected,
];
$p->waitList = $this->waitList;
$p->waitList[] = $this;
return $p;
}
// Return a fulfilled promise and immediately invoke any callbacks.
if ($this->state === self::FULFILLED) {
$promise = Create::promiseFor($this->result);
return $onFulfilled ? $promise->then($onFulfilled) : $promise;
}
// It's either cancelled or rejected, so return a rejected promise
// and immediately invoke any callbacks.
$rejection = Create::rejectionFor($this->result);
return $onRejected ? $rejection->then(null, $onRejected) : $rejection;
}