public function shutdown() : \Generator
{
if (!$this->context->isRunning() || $this->shutdown) {
throw new StatusError('The worker is not running.');
}
$this->shutdown = true;
// Cancel any waiting tasks.
$this->cancelPending();
// If a task is currently running, wait for it to finish.
if (null !== $this->active) {
try {
(yield $this->active);
} catch (\Throwable $exception) {
// Ignore failure in this context.
}
}
yield from $this->context->send(0);
return yield from $this->context->join();
}