Automattic\WooCommerce\Vendor\GraphQL

Deferred::__constructpublicWC 1.0

Create a new Deferred promise and enqueue its execution.

Method of the class: Deferred{}

No Hooks.

Returns

null. Nothing (null).

Usage

$Deferred = new Deferred();
$Deferred->__construct( $executor );
$executor(Executor) (required)
.

Deferred::__construct() code WC 10.9.4

public function __construct(callable $executor)
{
    $this->executor = $executor;

    SyncPromiseQueue::enqueue(function (): void {
        $executor = $this->executor;
        assert($executor !== null, 'Always set in constructor, this callback runs only once.');
        $this->executor = null;

        try {
            $this->resolve($executor());
        } catch (\Throwable $e) {
            $this->reject($e);
        }
    });
}