mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-25 04:44:03 +00:00
AsyncPool: Return whether there are tasks left to be collected from collectTasks()
this allows a while($pool->collectTasks()); style code.
This commit is contained in:
parent
bce126b6d0
commit
a52e4f0392
@ -225,8 +225,10 @@ class AsyncPool{
|
|||||||
* Collects finished and/or crashed tasks from the workers, firing their on-completion hooks where appropriate.
|
* Collects finished and/or crashed tasks from the workers, firing their on-completion hooks where appropriate.
|
||||||
*
|
*
|
||||||
* @throws \ReflectionException
|
* @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){
|
foreach($this->taskQueues as $worker => $queue){
|
||||||
$doGC = false;
|
$doGC = false;
|
||||||
while(!$queue->isEmpty()){
|
while(!$queue->isEmpty()){
|
||||||
@ -254,6 +256,7 @@ class AsyncPool{
|
|||||||
$task->onCompletion();
|
$task->onCompletion();
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
$more = true;
|
||||||
break; //current task is still running, skip to next worker
|
break; //current task is still running, skip to next worker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,6 +264,7 @@ class AsyncPool{
|
|||||||
$this->workers[$worker]->collect();
|
$this->workers[$worker]->collect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $more;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function shutdownUnusedWorkers() : int{
|
public function shutdownUnusedWorkers() : int{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user