Automattic\WooCommerce\Vendor\GraphQL\Executor\Promise

Promise{}WC 1.0

Convenience wrapper for promises represented by Promise Adapter.

No Hooks.

Usage

$Promise = new Promise();
// use class methods

Methods

  1. public __construct($adoptedPromise, PromiseAdapter $adapter)
  2. public then(?callable $onFulfilled = null, ?callable $onRejected = null)

Promise{} code WC 10.8.1

class Promise
{
    /** @var SyncPromise|ReactPromise<mixed>|AmpFuture<mixed>|AmpPromise<mixed> */
    public $adoptedPromise;

    private PromiseAdapter $adapter;

    /**
     * @param mixed $adoptedPromise
     *
     * @throws InvariantViolation
     */
    public function __construct($adoptedPromise, PromiseAdapter $adapter)
    {
        if ($adoptedPromise instanceof self) {
            $selfClass = self::class;
            throw new InvariantViolation("Expected promise from adapted system, got {$selfClass}.");
        }

        $this->adoptedPromise = $adoptedPromise;
        $this->adapter = $adapter;
    }

    public function then(?callable $onFulfilled = null, ?callable $onRejected = null): Promise
    {
        return $this->adapter->then($this, $onFulfilled, $onRejected);
    }
}