diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index c16400a3c..185fa69ee 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -2046,9 +2046,8 @@ class Server{ HandlerList::unregisterAll(); if($this->scheduler instanceof ServerScheduler){ - $this->getLogger()->debug("Stopping all tasks"); - $this->scheduler->cancelAllTasks(); - $this->scheduler->mainThreadHeartbeat(PHP_INT_MAX); + $this->getLogger()->debug("Shutting down task scheduler"); + $this->scheduler->shutdown(); } if($this->properties !== null and $this->properties->hasChanged()){ diff --git a/src/pocketmine/scheduler/AsyncPool.php b/src/pocketmine/scheduler/AsyncPool.php index 5bf93a97f..c04104fa2 100644 --- a/src/pocketmine/scheduler/AsyncPool.php +++ b/src/pocketmine/scheduler/AsyncPool.php @@ -183,4 +183,13 @@ class AsyncPool{ Timings::$schedulerAsyncTimer->stopTiming(); } + + public function shutdown() : void{ + $this->collectTasks(); + $this->removeTasks(); + foreach($this->workers as $worker){ + $worker->quit(); + } + $this->workers = []; + } } diff --git a/src/pocketmine/scheduler/ServerScheduler.php b/src/pocketmine/scheduler/ServerScheduler.php index 103824bee..47d464d30 100644 --- a/src/pocketmine/scheduler/ServerScheduler.php +++ b/src/pocketmine/scheduler/ServerScheduler.php @@ -310,6 +310,11 @@ class ServerScheduler{ return $handler; } + public function shutdown() : void{ + $this->cancelAllTasks(); + $this->asyncPool->shutdown(); + } + /** * @param int $currentTick */