class RejectedPromise in Auth0 Single Sign On 8.2
A promise that has been rejected.
Thenning off of this promise will invoke the onRejected callback immediately and ignore other callbacks.
Hierarchy
- class \GuzzleHttp\Promise\RejectedPromise implements PromiseInterface
Expanded class hierarchy of RejectedPromise
3 files declare their use of RejectedPromise
- Middleware.php in vendor/
guzzlehttp/ guzzle/ src/ Middleware.php - MockHandler.php in vendor/
guzzlehttp/ guzzle/ src/ Handler/ MockHandler.php - RetryMiddleware.php in vendor/
guzzlehttp/ guzzle/ src/ RetryMiddleware.php
File
- vendor/
guzzlehttp/ promises/ src/ RejectedPromise.php, line 10
Namespace
GuzzleHttp\PromiseView source
class RejectedPromise implements PromiseInterface {
private $reason;
public function __construct($reason) {
if (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) {
// 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 (\Throwable $e) {
// onRejected threw, so return a rejected promise.
$p
->reject($e);
} catch (\Exception $e) {
// onRejected threw, so return a rejected promise.
$p
->reject($e);
}
}
});
return $p;
}
public function otherwise(callable $onRejected) {
return $this
->then(null, $onRejected);
}
public function wait($unwrap = true, $defaultDelivery = null) {
if ($unwrap) {
throw exception_for($this->reason);
}
}
public function getState() {
return self::REJECTED;
}
public function resolve($value) {
throw new \LogicException("Cannot resolve a rejected promise");
}
public function reject($reason) {
if ($reason !== $this->reason) {
throw new \LogicException("Cannot reject a rejected promise");
}
}
public function cancel() {
// pass
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PromiseInterface:: |
constant | |||
PromiseInterface:: |
constant | |||
PromiseInterface:: |
constant | |||
RejectedPromise:: |
private | property | ||
RejectedPromise:: |
public | function |
Cancels the promise if possible. Overrides PromiseInterface:: |
|
RejectedPromise:: |
public | function |
Get the state of the promise ("pending", "rejected", or "fulfilled"). Overrides PromiseInterface:: |
|
RejectedPromise:: |
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:: |
|
RejectedPromise:: |
public | function |
Reject the promise with the given reason. Overrides PromiseInterface:: |
|
RejectedPromise:: |
public | function |
Resolve the promise with the given value. Overrides PromiseInterface:: |
|
RejectedPromise:: |
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:: |
|
RejectedPromise:: |
public | function |
Waits until the promise completes if possible. Overrides PromiseInterface:: |
|
RejectedPromise:: |
public | function |