You are here

class RejectedPromise in Lockr 7.3

A promise that has been rejected.

Thenning off of this promise will invoke the onRejected callback immediately and ignore other callbacks.

Hierarchy

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\Promise
View 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

Namesort descending Modifiers Type Description Overrides
PromiseInterface::FULFILLED constant
PromiseInterface::PENDING constant
PromiseInterface::REJECTED 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