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

Breadcrumb

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

interface PromiseInterface

Same name in this branch
  1. 11.1.x vendor/react/promise/src/PromiseInterface.php \React\Promise\PromiseInterface
  2. 11.1.x vendor/phpspec/prophecy/src/Prophecy/Promise/PromiseInterface.php \Prophecy\Promise\PromiseInterface

A promise represents the eventual result of an asynchronous operation.

The primary way of interacting with a promise is through its then method, which registers callbacks to receive either a promise’s eventual value or the reason why the promise cannot be fulfilled.

Hierarchy

  • interface \GuzzleHttp\Promise\PromiseInterface

Expanded class hierarchy of PromiseInterface

All classes that implement PromiseInterface

See also

https://promisesaplus.com/

16 files declare their use of PromiseInterface
Client.php in vendor/guzzlehttp/guzzle/src/Client.php
ClientInterface.php in vendor/guzzlehttp/guzzle/src/ClientInterface.php
ClientTrait.php in vendor/guzzlehttp/guzzle/src/ClientTrait.php
CurlFactory.php in vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php
CurlHandler.php in vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php

... See full list

File

vendor/guzzlehttp/promises/src/PromiseInterface.php, line 16

Namespace

GuzzleHttp\Promise
View source
interface PromiseInterface {
    public const PENDING = 'pending';
    public const FULFILLED = 'fulfilled';
    public const REJECTED = 'rejected';
    
    /**
     * Appends fulfillment and rejection handlers to the promise, and returns
     * a new promise resolving to the return value of the called handler.
     *
     * @param callable $onFulfilled Invoked when the promise fulfills.
     * @param callable $onRejected  Invoked when the promise is rejected.
     */
    public function then(?callable $onFulfilled = null, ?callable $onRejected = null) : PromiseInterface;
    
    /**
     * 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.
     *
     * @param callable $onRejected Invoked when the promise is rejected.
     */
    public function otherwise(callable $onRejected) : PromiseInterface;
    
    /**
     * Get the state of the promise ("pending", "rejected", or "fulfilled").
     *
     * The three states can be checked against the constants defined on
     * PromiseInterface: PENDING, FULFILLED, and REJECTED.
     */
    public function getState() : string;
    
    /**
     * Resolve the promise with the given value.
     *
     * @param mixed $value
     *
     * @throws \RuntimeException if the promise is already resolved.
     */
    public function resolve($value) : void;
    
    /**
     * Reject the promise with the given reason.
     *
     * @param mixed $reason
     *
     * @throws \RuntimeException if the promise is already resolved.
     */
    public function reject($reason) : void;
    
    /**
     * Cancels the promise if possible.
     *
     * @see https://github.com/promises-aplus/cancellation-spec/issues/7
     */
    public function cancel() : void;
    
    /**
     * Waits until the promise completes if possible.
     *
     * Pass $unwrap as true to unwrap the result of the promise, either
     * returning the resolved value or throwing the rejected exception.
     *
     * If the promise cannot be waited on, then the promise will be rejected.
     *
     * @return mixed
     *
     * @throws \LogicException if the promise has no wait function or if the
     *                         promise does not settle after waiting.
     */
    public function wait(bool $unwrap = true);

}

Members

Title Sort descending Modifiers Object type Summary Overrides
PromiseInterface::cancel public function Cancels the promise if possible. 4
PromiseInterface::FULFILLED public constant
PromiseInterface::getState public function Get the state of the promise ("pending", "rejected", or "fulfilled"). 4
PromiseInterface::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.
4
PromiseInterface::PENDING public constant
PromiseInterface::reject public function Reject the promise with the given reason. 4
PromiseInterface::REJECTED public constant
PromiseInterface::resolve public function Resolve the promise with the given value. 4
PromiseInterface::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.
4
PromiseInterface::wait public function Waits until the promise completes if possible. 4
RSS feed
Powered by Drupal