From d7e8a9de84815a4fcbc93adfe27609705c35face Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Thu, 16 Feb 2017 22:20:10 -0600 Subject: [PATCH] Calling stop() in nested loop should not stop outer loop --- lib/Loop.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Loop.php b/lib/Loop.php index 5184b60..d014b93 100644 --- a/lib/Loop.php +++ b/lib/Loop.php @@ -42,19 +42,19 @@ abstract class Loop extends Driver { private $errorHandler; /** - * @var bool + * @var int */ - private $running = false; + private $running = 0; /** * {@inheritdoc} */ public function run() { $previous = $this->running; - $this->running = true; + ++$this->running; try { - while ($this->running) { + while ($this->running > $previous) { if ($this->isEmpty()) { return; } @@ -69,7 +69,7 @@ abstract class Loop extends Driver { * {@inheritdoc} */ public function stop() { - $this->running = false; + --$this->running > 0 ?: $this->running = 0; } /** @@ -414,7 +414,7 @@ abstract class Loop extends Driver { "on_readable" => $onReadable, "on_writable" => $onWritable, "on_signal" => $onSignal, - "running" => $this->running, + "running" => (bool) $this->running, ]; }