public function RejectedPromise::then in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/guzzlehttp/promises/src/RejectedPromise.php \GuzzleHttp\Promise\RejectedPromise::then()
Appends fulfillment and rejection handlers to the promise, and returns a new promise resolving to the return value of the called handler.
Parameters
callable $onFulfilled Invoked when the promise fulfills.:
callable $onRejected Invoked when the promise is rejected.:
Return value
Overrides PromiseInterface::then
1 call to RejectedPromise::then()
- RejectedPromise::otherwise in vendor/
guzzlehttp/ promises/ src/ RejectedPromise.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/ RejectedPromise.php, line 24
Class
- RejectedPromise
- A promise that has been rejected.
Namespace
GuzzleHttp\PromiseCode
public function then(callable $onFulfilled = null, callable $onRejected = null) {
// If there's no onRejected callback then just return self.
if (!$onRejected) {
return $this;
}
$queue = queue();
$reason = $this->reason;
$p = new Promise([
$queue,
'run',
]);
$queue
->add(static function () use ($p, $reason, $onRejected) {
if ($p
->getState() === self::PENDING) {
try {
// Return a resolved promise if onRejected does not throw.
$p
->resolve($onRejected($reason));
} catch (\Exception $e) {
// onRejected threw, so return a rejected promise.
$p
->reject($e);
}
}
});
return $p;
}