From bad19256e76b2bad171860f631e002563fd16216 Mon Sep 17 00:00:00 2001 From: chaz6chez Date: Fri, 8 Nov 2024 09:48:43 +0800 Subject: [PATCH] fix WaitGroup misuse: negative counter --- src/Utils/WaitGroup/Handlers/SwooleWaitGroup.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Utils/WaitGroup/Handlers/SwooleWaitGroup.php b/src/Utils/WaitGroup/Handlers/SwooleWaitGroup.php index c745bdf..6129dc2 100644 --- a/src/Utils/WaitGroup/Handlers/SwooleWaitGroup.php +++ b/src/Utils/WaitGroup/Handlers/SwooleWaitGroup.php @@ -37,7 +37,7 @@ public function __destruct() /** @inheritdoc */ public function add(int $delta = 1): bool { - $this->_waitGroup->add($delta); + $this->_waitGroup->add(max($delta, 1)); return true; } @@ -45,7 +45,9 @@ public function add(int $delta = 1): bool /** @inheritdoc */ public function done(): bool { - $this->_waitGroup->done(); + if ($this->count() > 0) { + $this->_waitGroup->done(); + } return true; }