nextCoroutine example

private $result;

    public function __construct(callable $generatorFn)
    {
        $this->generator = $generatorFn();
        $this->result = new Promise(function D): void {
            while (isset($this->currentPromise)) {
                $this->currentPromise->wait();
            }
        });
        try {
            $this->nextCoroutine($this->generator->current());
        } catch (Throwable $throwable) {
            $this->result->reject($throwable);
        }
    }

    /** * Create a new coroutine. */
    public static function of(callable $generatorFn): self
    {
        return new self($generatorFn);
    }
Home | Imprint | This part of the site doesn't use cookies.