class RejectedPromise
Same name in this branch
- 11.1.x vendor/react/promise/src/Internal/RejectedPromise.php \React\Promise\Internal\RejectedPromise
- 11.1.x vendor/php-http/promise/src/RejectedPromise.php \Http\Promise\RejectedPromise
A promise that has been rejected.
Thenning off of this promise will invoke the onRejected callback immediately and ignore other callbacks.
@final
Hierarchy
- class \GuzzleHttp\Promise\RejectedPromise implements \GuzzleHttp\Promise\PromiseInterface
Expanded class hierarchy of RejectedPromise
File
-
vendor/
guzzlehttp/ promises/ src/ RejectedPromise.php, line 15
Namespace
GuzzleHttp\PromiseView source
class RejectedPromise implements PromiseInterface {
private $reason;
/**
* @param mixed $reason
*/
public function __construct($reason) {
if (is_object($reason) && method_exists($reason, 'then')) {
throw new \InvalidArgumentException('You cannot create a RejectedPromise with a promise.');
}
$this->reason = $reason;
}
public function then(?callable $onFulfilled = null, ?callable $onRejected = null) : PromiseInterface {
// If there's no onRejected callback then just return self.
if (!$onRejected) {
return $this;
}
$queue = Utils::queue();
$reason = $this->reason;
$p = new Promise([
$queue,
'run',
]);
$queue->add(static function () use ($p, $reason, $onRejected) : void {
if (Is::pending($p)) {
try {
// Return a resolved promise if onRejected does not throw.
$p->resolve($onRejected($reason));
} catch (\Throwable $e) {
// onRejected threw, so return a rejected promise.
$p->reject($e);
}
}
});
return $p;
}
public function otherwise(callable $onRejected) : PromiseInterface {
return $this->then(null, $onRejected);
}
public function wait(bool $unwrap = true) {
if ($unwrap) {
throw Create::exceptionFor($this->reason);
}
return null;
}
public function getState() : string {
return self::REJECTED;
}
public function resolve($value) : void {
throw new \LogicException('Cannot resolve a rejected promise');
}
public function reject($reason) : void {
if ($reason !== $this->reason) {
throw new \LogicException('Cannot reject a rejected promise');
}
}
public function cancel() : void {
// pass
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
PromiseInterface::FULFILLED | public | constant | ||
PromiseInterface::PENDING | public | constant | ||
PromiseInterface::REJECTED | public | constant | ||
RejectedPromise::$reason | private | property | ||
RejectedPromise::cancel | public | function | Cancels the promise if possible. | Overrides PromiseInterface::cancel |
RejectedPromise::getState | public | function | Get the state of the promise ("pending", "rejected", or "fulfilled"). | Overrides PromiseInterface::getState |
RejectedPromise::otherwise | public | function | 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. |
Overrides PromiseInterface::otherwise |
RejectedPromise::reject | public | function | Reject the promise with the given reason. | Overrides PromiseInterface::reject |
RejectedPromise::resolve | public | function | Resolve the promise with the given value. | Overrides PromiseInterface::resolve |
RejectedPromise::then | public | function | Appends fulfillment and rejection handlers to the promise, and returns a new promise resolving to the return value of the called handler. |
Overrides PromiseInterface::then |
RejectedPromise::wait | public | function | Waits until the promise completes if possible. | Overrides PromiseInterface::wait |
RejectedPromise::__construct | public | function |