From a52e4f03928dab740bc1016493067899d43dd600 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 8 Aug 2019 18:48:58 +0100 Subject: [PATCH] AsyncPool: Return whether there are tasks left to be collected from collectTasks() this allows a while($pool->collectTasks()); style code. --- src/scheduler/AsyncPool.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/scheduler/AsyncPool.php b/src/scheduler/AsyncPool.php index 838a49dc91..403703d419 100644 --- a/src/scheduler/AsyncPool.php +++ b/src/scheduler/AsyncPool.php @@ -225,8 +225,10 @@ class AsyncPool{ * Collects finished and/or crashed tasks from the workers, firing their on-completion hooks where appropriate. * * @throws \ReflectionException + * @return bool whether there are tasks left to be collected */ - public function collectTasks() : void{ + public function collectTasks() : bool{ + $more = false; foreach($this->taskQueues as $worker => $queue){ $doGC = false; while(!$queue->isEmpty()){ @@ -254,6 +256,7 @@ class AsyncPool{ $task->onCompletion(); } }else{ + $more = true; break; //current task is still running, skip to next worker } } @@ -261,6 +264,7 @@ class AsyncPool{ $this->workers[$worker]->collect(); } } + return $more; } public function shutdownUnusedWorkers() : int{