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

Breadcrumb

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

function FulfilledPromise::then

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

Overrides PromiseInterface::then

1 call to FulfilledPromise::then()
FulfilledPromise::otherwise in vendor/guzzlehttp/promises/src/FulfilledPromise.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/FulfilledPromise.php, line 33

Class

FulfilledPromise
A promise that has been fulfilled.

Namespace

GuzzleHttp\Promise

Code

public function then(?callable $onFulfilled = null, ?callable $onRejected = null) : PromiseInterface {
    // Return itself if there is no onFulfilled function.
    if (!$onFulfilled) {
        return $this;
    }
    $queue = Utils::queue();
    $p = new Promise([
        $queue,
        'run',
    ]);
    $value = $this->value;
    $queue->add(static function () use ($p, $value, $onFulfilled) : void {
        if (Is::pending($p)) {
            try {
                $p->resolve($onFulfilled($value));
            } catch (\Throwable $e) {
                $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