mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-28 06:09:57 +00:00
Be sure that AsyncTask finish executing, fixes #2931
This commit is contained in:
parent
7ad98d4659
commit
fba12f2a13
@ -1994,25 +1994,32 @@ class Server{
|
||||
UPnP::RemovePortForward($this->getPort());
|
||||
}
|
||||
|
||||
$this->getLogger()->debug("Disabling all plugins");
|
||||
$this->pluginManager->disablePlugins();
|
||||
|
||||
foreach($this->players as $player){
|
||||
$player->close($player->getLeaveMessage(), $this->getProperty("settings.shutdown-message", "Server closed"));
|
||||
}
|
||||
|
||||
$this->getLogger()->debug("Unloading all levels");
|
||||
foreach($this->getLevels() as $level){
|
||||
$this->unloadLevel($level, true);
|
||||
}
|
||||
|
||||
$this->getLogger()->debug("Removing event handlers");
|
||||
HandlerList::unregisterAll();
|
||||
|
||||
$this->getLogger()->debug("Stopping all tasks");
|
||||
$this->scheduler->cancelAllTasks();
|
||||
$this->scheduler->mainThreadHeartbeat(PHP_INT_MAX);
|
||||
|
||||
$this->getLogger()->debug("Saving properties");
|
||||
$this->properties->save();
|
||||
|
||||
$this->getLogger()->debug("Closing console");
|
||||
$this->console->kill();
|
||||
|
||||
$this->getLogger()->debug("Stopping network interfaces");
|
||||
foreach($this->network->getInterfaces() as $interface){
|
||||
$interface->shutdown();
|
||||
$this->network->unregisterInterface($interface);
|
||||
|
@ -106,6 +106,9 @@ class AsyncPool{
|
||||
|
||||
private function removeTask(AsyncTask $task){
|
||||
if(isset($this->taskWorkers[$task->getTaskId()])){
|
||||
if($task->isRunning() or !$task->isGarbage()){
|
||||
return;
|
||||
}
|
||||
$this->workers[$w = $this->taskWorkers[$task->getTaskId()]]->unstack($task);
|
||||
$this->workerUsage[$w]--;
|
||||
}
|
||||
@ -119,10 +122,16 @@ class AsyncPool{
|
||||
}
|
||||
|
||||
public function removeTasks(){
|
||||
do{
|
||||
foreach($this->tasks as $task){
|
||||
$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;
|
||||
}
|
||||
@ -135,7 +144,7 @@ class AsyncPool{
|
||||
Timings::$schedulerAsyncTimer->startTiming();
|
||||
|
||||
foreach($this->tasks as $task){
|
||||
if($task->isGarbage()){
|
||||
if($task->isGarbage() and !$task->isRunning()){
|
||||
|
||||
$task->onCompletion($this->server);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user