1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 21:31:18 +01:00

Fix throw from send

This commit is contained in:
Aaron Piotrowski 2020-09-25 12:57:56 -05:00
parent 72b50523a3
commit b35c9f1956
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB

View File

@ -41,16 +41,21 @@ final class AsyncGenerator implements Pipeline
while ($generator->valid()) { while ($generator->valid()) {
try { try {
$yielded = $generator->send(await($source->emit($yielded))); $yielded = await($source->emit($yielded));
} catch (DisposedException $exception) {
throw $exception; // Destroys generator and fails pipeline.
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$yielded = $generator->throw($exception); $yielded = $generator->throw($exception);
continue;
} }
$yielded = $generator->send($yielded);
} }
return $generator->getReturn(); return $generator->getReturn();
}); });
$this->promise->onResolve(static function ($exception) use ($source): void { $this->promise->onResolve(static function (?\Throwable $exception) use ($source): void {
if ($source->isDisposed()) { if ($source->isDisposed()) {
return; // AsyncGenerator object was destroyed. return; // AsyncGenerator object was destroyed.
} }
@ -91,7 +96,7 @@ final class AsyncGenerator implements Pipeline
* *
* @throws \Error If the first emitted value has not been retrieved using {@see continue()}. * @throws \Error If the first emitted value has not been retrieved using {@see continue()}.
*/ */
public function send($value): mixed public function send(mixed $value): mixed
{ {
return $this->source->send($value); return $this->source->send($value);
} }