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

SyncPromise::enqueueWaitingPromisesprivateWC 1.0

Method of the class: SyncPromise{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->enqueueWaitingPromises(): void;

SyncPromise::enqueueWaitingPromises() code WC 10.9.1

private function enqueueWaitingPromises(): void
{
    if ($this->state === self::PENDING) {
        throw new InvariantViolation('Cannot enqueue derived promises when parent is still pending.');
    }

    $waiting = $this->waiting;
    if ($waiting === []) {
        return;
    }

    $this->waiting = [];

    $result = $this->result;

    SyncPromiseQueue::enqueue(static function () use ($waiting, $result): void {
        foreach ($waiting as [$child, $onFulfilled, $onRejected]) {
            try {
                if ($result instanceof \Throwable) {
                    if ($onRejected === null) {
                        $child->reject($result);
                    } else {
                        $child->resolve($onRejected($result));
                    }
                } else {
                    $child->resolve(
                        $onFulfilled === null
                            ? $result
                            : $onFulfilled($result)
                    );
                }
            } catch (\Throwable $e) {
                $child->reject($e);
            }
        }
    });
}