Amp\Coroutine::dispose PHP Method

dispose() private method

Runs the generator to completion then fails the coroutine with the given exception.
private dispose ( Throwable $exception )
$exception Throwable
    private function dispose(\Throwable $exception)
    {
        if ($this->generator->valid()) {
            try {
                try {
                    // Ensure generator has run to completion to avoid throws from finally blocks on destruction.
                    do {
                        $this->generator->throw($exception);
                    } while ($this->generator->valid());
                } finally {
                    // Throw from finally to attach any exception thrown from generator as previous exception.
                    throw $exception;
                }
            } catch (\Throwable $exception) {
                // $exception will be used to fail the coroutine.
            }
        }
        $this->fail($exception);
    }