Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. RejectedPromise.php

function RejectedPromise::then

Same name in this branch
  1. 11.1.x vendor/react/promise/src/Internal/RejectedPromise.php \React\Promise\Internal\RejectedPromise::then()
  2. 11.1.x vendor/php-http/promise/src/RejectedPromise.php \Http\Promise\RejectedPromise::then()

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 33

Class

RejectedPromise
A promise that has been rejected.

Namespace

GuzzleHttp\Promise

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal