mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-30 23:29:54 +00:00
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:
parent
532d57eec7
commit
f245147c11
@ -233,11 +233,17 @@ class AsyncPool{
|
|||||||
* @return bool whether there are tasks left to be collected
|
* @return bool whether there are tasks left to be collected
|
||||||
*/
|
*/
|
||||||
public function collectTasks() : bool{
|
public function collectTasks() : bool{
|
||||||
$more = false;
|
|
||||||
foreach($this->taskQueues as $worker => $queue){
|
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{
|
public function collectTasksFromWorker(int $worker) : bool{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user