Automattic\WooCommerce\Vendor\GraphQL\Executor\Promise\Adapter

ReactPromiseAdapter{}WC 1.0└─ PromiseAdapter

No Hooks.

Usage

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

Methods

  1. public all(iterable $promisesOrValues)
  2. public convertThenable($thenable)
  3. public create(callable $resolver)
  4. public createFulfilled($value = null)
  5. public createRejected(\Throwable $reason)
  6. public isThenable($value)
  7. public then(Promise $promise, ?callable $onFulfilled = null, ?callable $onRejected = null)

ReactPromiseAdapter{} code WC 10.9.4

class ReactPromiseAdapter implements PromiseAdapter
{
    public function isThenable($value): bool
    {
        return $value instanceof ReactPromiseInterface;
    }

    /** @throws InvariantViolation */
    public function convertThenable($thenable): Promise
    {
        return new Promise($thenable, $this);
    }

    /** @throws InvariantViolation */
    public function then(Promise $promise, ?callable $onFulfilled = null, ?callable $onRejected = null): Promise
    {
        $reactPromise = $promise->adoptedPromise;
        assert($reactPromise instanceof ReactPromiseInterface);

        return new Promise($reactPromise->then($onFulfilled, $onRejected), $this);
    }

    /** @throws InvariantViolation */
    public function create(callable $resolver): Promise
    {
        $reactPromise = new ReactPromise($resolver);

        return new Promise($reactPromise, $this);
    }

    /** @throws InvariantViolation */
    public function createFulfilled($value = null): Promise
    {
        $reactPromise = resolve($value);

        return new Promise($reactPromise, $this);
    }

    /** @throws InvariantViolation */
    public function createRejected(\Throwable $reason): Promise
    {
        $reactPromise = reject($reason);

        return new Promise($reactPromise, $this);
    }

    /** @throws InvariantViolation */
    public function all(iterable $promisesOrValues): Promise
    {
        foreach ($promisesOrValues as &$promiseOrValue) {
            if ($promiseOrValue instanceof Promise) {
                $promiseOrValue = $promiseOrValue->adoptedPromise;
            }
        }

        $promisesOrValuesArray = is_array($promisesOrValues)
            ? $promisesOrValues
            : iterator_to_array($promisesOrValues);
        $reactPromise = all($promisesOrValuesArray)->then(static fn (array $values): array => array_map(
            static fn ($key) => $values[$key],
            array_keys($promisesOrValuesArray),
        ));

        return new Promise($reactPromise, $this);
    }
}