Skip to content

Commit

Permalink
Fix DefaultPool::shutdown()
Browse files Browse the repository at this point in the history
Forgot to update this to match Worker::shutdown() behavior.
  • Loading branch information
trowski committed Oct 27, 2018
1 parent eff56fb commit 4c3c93e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 6 additions & 3 deletions lib/Worker/DefaultPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ final class DefaultPool implements Pool
/** @var \Closure */
private $push;

/** @var \Amp\Promise|null */
private $exitStatus;

/**
* Creates a new worker pool.
*
Expand Down Expand Up @@ -162,8 +165,8 @@ public function enqueue(Task $task): Promise
*/
public function shutdown(): Promise
{
if (!$this->isRunning()) {
throw new StatusError("The pool was shutdown");
if ($this->exitStatus) {
return $this->exitStatus;
}

$this->running = false;
Expand All @@ -175,7 +178,7 @@ public function shutdown(): Promise
}
}

return Promise\all($shutdowns);
return $this->exitStatus = Promise\all($shutdowns);
}

/**
Expand Down
10 changes: 3 additions & 7 deletions test/Worker/AbstractPoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,15 @@ public function testIsIdleOnStart()
});
}

/**
* @expectedException \Amp\Parallel\Context\StatusError
* @expectedExceptionMessage The pool was shutdown
*/
public function testShutdownShouldThrowStatusError()
public function testShutdownShouldReturnSameResult()
{
Loop::run(function () {
$pool = $this->createPool();

$this->assertTrue($pool->isIdle());

yield $pool->shutdown();
yield $pool->shutdown();
$result = yield $pool->shutdown();
$this->assertSame($result, yield $pool->shutdown());
});
}

Expand Down

0 comments on commit 4c3c93e

Please sign in to comment.