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

Breadcrumb

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

function Promise::then

Same name in this branch
  1. 11.1.x vendor/react/promise/src/Promise.php \React\Promise\Promise::then()
  2. 11.1.x vendor/php-http/guzzle7-adapter/src/Promise.php \Http\Adapter\Guzzle7\Promise::then()
  3. 11.1.x vendor/php-http/promise/src/Promise.php \Http\Promise\Promise::then()

Overrides PromiseInterface::then

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

Class

Promise
Promises/A+ implementation that avoids recursion when possible.

Namespace

GuzzleHttp\Promise

Code

public function then(?callable $onFulfilled = null, ?callable $onRejected = null) : PromiseInterface {
    if ($this->state === self::PENDING) {
        $p = new Promise(null, [
            $this,
            'cancel',
        ]);
        $this->handlers[] = [
            $p,
            $onFulfilled,
            $onRejected,
        ];
        $p->waitList = $this->waitList;
        $p->waitList[] = $this;
        return $p;
    }
    // Return a fulfilled promise and immediately invoke any callbacks.
    if ($this->state === self::FULFILLED) {
        $promise = Create::promiseFor($this->result);
        return $onFulfilled ? $promise->then($onFulfilled) : $promise;
    }
    // It's either cancelled or rejected, so return a rejected promise
    // and immediately invoke any callbacks.
    $rejection = Create::rejectionFor($this->result);
    return $onRejected ? $rejection->then(null, $onRejected) : $rejection;
}

API Navigation

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