Skip to content

Commit

Permalink
Fix double wait, improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
twose committed Mar 9, 2020
1 parent 96e8edf commit 537a82e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/core/Coroutine/WaitGroup.php
Expand Up @@ -34,7 +34,7 @@ public function add(int $delta = 1): void
}
$count = $this->count + $delta;
if ($count < 0) {
throw new InvalidArgumentException('negative WaitGroup counter');
throw new InvalidArgumentException('WaitGroup misuse: negative counter');
}
$this->count = $count;
}
Expand All @@ -43,7 +43,7 @@ public function done(): void
{
$count = $this->count - 1;
if ($count < 0) {
throw new BadMethodCallException('negative WaitGroup counter');
throw new BadMethodCallException('WaitGroup misuse: negative counter');
}
$this->count = $count;
if ($count === 0 && $this->waiting) {
Expand All @@ -53,6 +53,9 @@ public function done(): void

public function wait(float $timeout = -1): bool
{
if ($this->waiting) {
throw new BadMethodCallException('WaitGroup misuse: reused before previous wait has returned');
}
if ($this->count > 0) {
$this->waiting = true;
$done = $this->chan->pop($timeout);
Expand Down

0 comments on commit 537a82e

Please sign in to comment.