From 3fb87e2c1868ddca7dc6dbbf93cc7897458a2af2 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Fri, 17 Jul 2020 11:19:36 -0500 Subject: [PATCH] Fix Psalm errors --- lib/AsyncGenerator.php | 7 ++++++- lib/Deferred.php | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/AsyncGenerator.php b/lib/AsyncGenerator.php index 8ef0a2d..2fb99b4 100644 --- a/lib/AsyncGenerator.php +++ b/lib/AsyncGenerator.php @@ -12,7 +12,7 @@ final class AsyncGenerator implements Stream /** @var Internal\EmitSource */ private $source; - /** @var Promise */ + /** @var Coroutine|null */ private $coroutine; /** @var \Generator|null */ @@ -121,11 +121,16 @@ final class AsyncGenerator implements Stream return $this->coroutine; } + /** @psalm-suppress PossiblyNullArgument */ $this->coroutine = new Coroutine($this->generator); $this->generator = null; $source = $this->source; $this->coroutine->onResolve(static function ($exception) use ($source) { + if ($source->isComplete()) { + return; // AsyncGenerator object was destroyed. + } + if ($exception) { $source->fail($exception); return; diff --git a/lib/Deferred.php b/lib/Deferred.php index 8f2ed0f..84d8d6b 100644 --- a/lib/Deferred.php +++ b/lib/Deferred.php @@ -43,6 +43,7 @@ final class Deferred */ public function isResolved(): bool { + /** @psalm-suppress UndefinedInterfaceMethod */ return $this->resolver->isResolved(); }