Skip to content

Commit

Permalink
Better pool shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 27, 2023
1 parent 470293d commit 48653bc
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/Worker/ContextWorkerPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,12 @@ public function shutdown(): void
);
}

$workers = $this->workers;
($this->exitStatus = async(static function () use ($workers): void {
foreach ($workers as $worker) {
\assert($worker instanceof Worker);
if ($worker->isRunning()) {
$worker->shutdown();
}
}
}))->await();
$futures = \array_map(
static fn (Worker $worker) => async($worker->shutdown(...)),
\iterator_to_array($this->workers),
);

($this->exitStatus = async(Future\awaitAll(...), $futures)->map(static fn () => null))->await();
}

/**
Expand Down

0 comments on commit 48653bc

Please sign in to comment.