AsyncPool: Always collect workers, even if the task queue is empty

because of the way async tasks are processed, we might collect results from a task before it's able to be collected by collect(). Therefore, the queue might be empty, even though there are still tasks to be collected.
This commit is contained in:
Dylan K. Taylor 2021-02-04 21:43:53 +00:00
parent 27b1951df7
commit 54d9342ed9
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -245,14 +245,12 @@ class AsyncPool{
throw new \InvalidArgumentException("No such worker $worker");
}
$queue = $this->taskQueues[$worker];
$doGC = false;
$more = false;
while(!$queue->isEmpty()){
/** @var AsyncTask $task */
$task = $queue->bottom();
$task->checkProgressUpdates();
if($task->isFinished()){ //make sure the task actually executed before trying to collect
$doGC = true;
$queue->dequeue();
if($task->isCrashed()){
@ -276,9 +274,7 @@ class AsyncPool{
break; //current task is still running, skip to next worker
}
}
if($doGC){
$this->workers[$worker]->collect();
}
$this->workers[$worker]->collect();
return $more;
}