Skip to content

Commit 537a82e

Browse files
committed
Fix double wait, improve error message
1 parent 96e8edf commit 537a82e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/core/Coroutine/WaitGroup.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function add(int $delta = 1): void
3434
}
3535
$count = $this->count + $delta;
3636
if ($count < 0) {
37-
throw new InvalidArgumentException('negative WaitGroup counter');
37+
throw new InvalidArgumentException('WaitGroup misuse: negative counter');
3838
}
3939
$this->count = $count;
4040
}
@@ -43,7 +43,7 @@ public function done(): void
4343
{
4444
$count = $this->count - 1;
4545
if ($count < 0) {
46-
throw new BadMethodCallException('negative WaitGroup counter');
46+
throw new BadMethodCallException('WaitGroup misuse: negative counter');
4747
}
4848
$this->count = $count;
4949
if ($count === 0 && $this->waiting) {
@@ -53,6 +53,9 @@ public function done(): void
5353

5454
public function wait(float $timeout = -1): bool
5555
{
56+
if ($this->waiting) {
57+
throw new BadMethodCallException('WaitGroup misuse: reused before previous wait has returned');
58+
}
5659
if ($this->count > 0) {
5760
$this->waiting = true;
5861
$done = $this->chan->pop($timeout);

0 commit comments

Comments
 (0)