From eec21c12c668fafb9934ee692b62a93f5974373f Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Thu, 22 Oct 2020 23:03:58 -0500 Subject: [PATCH] Fix use before init --- lib/CombinedCancellationToken.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/CombinedCancellationToken.php b/lib/CombinedCancellationToken.php index d9753e5..34033ed 100644 --- a/lib/CombinedCancellationToken.php +++ b/lib/CombinedCancellationToken.php @@ -12,12 +12,12 @@ final class CombinedCancellationToken implements CancellationToken /** @var callable[] */ private array $callbacks = []; - private ?CancelledException $exception; + private CancelledException $exception; public function __construct(CancellationToken ...$tokens) { foreach ($tokens as $token) { - $id = $token->subscribe(function (CancelledException $exception) { + $id = $token->subscribe(function (CancelledException $exception): void { $this->exception = $exception; $callbacks = $this->callbacks; @@ -45,8 +45,8 @@ final class CombinedCancellationToken implements CancellationToken { $id = $this->nextId++; - if ($this->exception) { - Loop::defer(static fn (): Promise => call($callback)($this->exception)); + if (isset($this->exception)) { + Loop::defer(static fn (): Promise => call($callback, $this->exception)); } else { $this->callbacks[$id] = $callback; }