1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-26 20:34:40 +01:00

Wait for pending task in shutdown

This commit is contained in:
Aaron Piotrowski 2018-12-30 12:48:54 -06:00
parent d7697ebd69
commit 2ac081575e
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB

View File

@ -38,13 +38,18 @@ abstract class TaskWorker implements Worker
$this->context = $context;
$context = &$this->context;
\register_shutdown_function(static function () use (&$context) {
$pending = &$this->pending;
\register_shutdown_function(static function () use (&$context, &$pending) {
if ($context === null || !$context->isRunning()) {
return;
}
try {
Promise\wait(Promise\timeout(call(function () use ($context) {
Promise\wait(Promise\timeout(call(function () use ($context, $pending) {
if ($pending) {
yield $pending;
}
yield $context->send(0);
return yield $context->join();
}), self::SHUTDOWN_TIMEOUT));