From 4faeca163b7034da56bc94a09cbae664b2dbc3f7 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Mon, 20 Apr 2020 12:01:50 -0500 Subject: [PATCH] Fix ref/unref of Delayed after resolving --- lib/Delayed.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Delayed.php b/lib/Delayed.php index 1372042..790c571 100644 --- a/lib/Delayed.php +++ b/lib/Delayed.php @@ -12,7 +12,7 @@ final class Delayed implements Promise { use Internal\Placeholder; - /** @var string Event loop watcher identifier. */ + /** @var string|null Event loop watcher identifier. */ private $watcher; /** @@ -22,6 +22,7 @@ final class Delayed implements Promise public function __construct(int $time, $value = null) { $this->watcher = Loop::delay($time, function () use ($value) { + $this->watcher = null; $this->resolve($value); }); } @@ -33,7 +34,9 @@ final class Delayed implements Promise */ public function reference() { - Loop::reference($this->watcher); + if ($this->watcher !== null) { + Loop::reference($this->watcher); + } } /** @@ -44,6 +47,8 @@ final class Delayed implements Promise */ public function unreference() { - Loop::unreference($this->watcher); + if ($this->watcher !== null) { + Loop::unreference($this->watcher); + } } }