mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-28 06:09:57 +00:00
AsyncPool: Move removeTasks() functionality inside shutdown()
there's no need for a loop if we just have the workers shutdown directly, because they'll block until all tasks are done anyway.
This commit is contained in:
parent
653fa1213e
commit
e0574008b4
@ -232,41 +232,6 @@ class AsyncPool{
|
|||||||
unset($this->taskWorkers[$task->getTaskId()]);
|
unset($this->taskWorkers[$task->getTaskId()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes all tasks from the pool, cancelling where possible. This will block until all tasks have been
|
|
||||||
* successfully deleted.
|
|
||||||
*/
|
|
||||||
public function removeTasks() : void{
|
|
||||||
foreach($this->workers as $worker){
|
|
||||||
/** @var AsyncTask $task */
|
|
||||||
while(($task = $worker->unstack()) !== null){
|
|
||||||
//cancelRun() is not strictly necessary here, but it might be used to inform plugins of the task state
|
|
||||||
//(i.e. it never executed).
|
|
||||||
$task->cancelRun();
|
|
||||||
$this->removeTask($task, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
do{
|
|
||||||
foreach($this->tasks as $task){
|
|
||||||
$task->cancelRun();
|
|
||||||
$this->removeTask($task);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(count($this->tasks) > 0){
|
|
||||||
usleep(25000);
|
|
||||||
}
|
|
||||||
}while(count($this->tasks) > 0);
|
|
||||||
|
|
||||||
for($i = 0; $i < $this->size; ++$i){
|
|
||||||
$this->workerUsage[$i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->taskWorkers = [];
|
|
||||||
$this->tasks = [];
|
|
||||||
|
|
||||||
$this->collectWorkers();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects garbage from running workers.
|
* Collects garbage from running workers.
|
||||||
*/
|
*/
|
||||||
@ -329,10 +294,28 @@ class AsyncPool{
|
|||||||
*/
|
*/
|
||||||
public function shutdown() : void{
|
public function shutdown() : void{
|
||||||
$this->collectTasks();
|
$this->collectTasks();
|
||||||
$this->removeTasks();
|
|
||||||
|
foreach($this->workers as $worker){
|
||||||
|
/** @var AsyncTask $task */
|
||||||
|
while(($task = $worker->unstack()) !== null){
|
||||||
|
//cancelRun() is not strictly necessary here, but it might be used to inform plugins of the task state
|
||||||
|
//(i.e. it never executed).
|
||||||
|
$task->cancelRun();
|
||||||
|
$this->removeTask($task, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach($this->tasks as $task){
|
||||||
|
$task->cancelRun();
|
||||||
|
$this->removeTask($task, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->taskWorkers = [];
|
||||||
|
$this->tasks = [];
|
||||||
|
|
||||||
foreach($this->workers as $worker){
|
foreach($this->workers as $worker){
|
||||||
$worker->quit();
|
$worker->quit();
|
||||||
}
|
}
|
||||||
$this->workers = [];
|
$this->workers = [];
|
||||||
|
$this->workerUsage = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user