mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-09 11:31:49 +00:00
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:
parent
27b1951df7
commit
54d9342ed9
@ -245,14 +245,12 @@ class AsyncPool{
|
|||||||
throw new \InvalidArgumentException("No such worker $worker");
|
throw new \InvalidArgumentException("No such worker $worker");
|
||||||
}
|
}
|
||||||
$queue = $this->taskQueues[$worker];
|
$queue = $this->taskQueues[$worker];
|
||||||
$doGC = false;
|
|
||||||
$more = false;
|
$more = false;
|
||||||
while(!$queue->isEmpty()){
|
while(!$queue->isEmpty()){
|
||||||
/** @var AsyncTask $task */
|
/** @var AsyncTask $task */
|
||||||
$task = $queue->bottom();
|
$task = $queue->bottom();
|
||||||
$task->checkProgressUpdates();
|
$task->checkProgressUpdates();
|
||||||
if($task->isFinished()){ //make sure the task actually executed before trying to collect
|
if($task->isFinished()){ //make sure the task actually executed before trying to collect
|
||||||
$doGC = true;
|
|
||||||
$queue->dequeue();
|
$queue->dequeue();
|
||||||
|
|
||||||
if($task->isCrashed()){
|
if($task->isCrashed()){
|
||||||
@ -276,9 +274,7 @@ class AsyncPool{
|
|||||||
break; //current task is still running, skip to next worker
|
break; //current task is still running, skip to next worker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($doGC){
|
|
||||||
$this->workers[$worker]->collect();
|
$this->workers[$worker]->collect();
|
||||||
}
|
|
||||||
return $more;
|
return $more;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user