AsyncPool: make collectTasks() return value more accurate

during onCompletion() anything may happen, including scheduling new tasks, which the previous code did not account for.
This commit is contained in:
Dylan K. Taylor 2021-06-11 18:27:43 +01:00
parent 532d57eec7
commit f245147c11
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -233,11 +233,17 @@ class AsyncPool{
* @return bool whether there are tasks left to be collected
*/
public function collectTasks() : bool{
$more = false;
foreach($this->taskQueues as $worker => $queue){
$more = $this->collectTasksFromWorker($worker) || $more;
$this->collectTasksFromWorker($worker);
}
return $more;
//we check this in a second loop, because task collection could have caused new tasks to be added to the queues
foreach($this->taskQueues as $queue){
if(!$queue->isEmpty()){
return true;
}
}
return false;
}
public function collectTasksFromWorker(int $worker) : bool{