public function wait(Promise $promise, callable $onProgress = null): ?ExecutionResult
    {
        if (!$this->isThenable($promise)) {
            throw new \InvalidArgumentException(\sprintf('The "%s" method must be call with compatible a Promise.', __METHOD__));
        }
        $wait = true;
        $resolvedValue = null;
        $exception = null;
        /** @var \React\Promise\PromiseInterface $reactPromise */
        $reactPromise = $promise->adoptedPromise;

        $reactPromise->then(function ($values) use (&$resolvedValue, &$wait): void {
            $resolvedValue = $values;
            $wait = false;
        }, function ($reason) use (&$exception, &$wait): void {
            $exception = $reason;
            $wait = false;
        });

        // wait until promise resolution
        while ($wait) {
            if (null !== $onProgress) {
                $onProgress();
            }
            // less CPU intensive without sacrificing the performance
            \usleep(5);
        }

        /** @var \Exception|null $exception */
        if (null !== $exception) {
            throw $exception;
        }

        return $resolvedValue;
    }