pocketmine\scheduler\ServerScheduler::cancelAllTasks PHP Method

cancelAllTasks() public method

public cancelAllTasks ( )
    public function cancelAllTasks()
    {
        foreach ($this->tasks as $task) {
            $task->cancel();
        }
        $this->tasks = [];
        $this->asyncPool->removeTasks();
        while (!$this->queue->isEmpty()) {
            $this->queue->extract();
        }
        $this->ids = 1;
    }

Usage Example

Example #1
0
 public function forceShutdown()
 {
     if ($this->hasStopped) {
         return;
     }
     try {
         if (!$this->isRunning()) {
             $this->sendUsage(SendUsageTask::TYPE_CLOSE);
         }
         $this->hasStopped = true;
         $this->shutdown();
         if ($this->rcon instanceof RCON) {
             $this->rcon->stop();
         }
         if ($this->getProperty("network.upnp-forwarding", false) === true) {
             $this->logger->info("[UPnP] Removing port forward...");
             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);
         }
         $this->memoryManager->doObjectCleanup();
         gc_collect_cycles();
     } catch (\Exception $e) {
         $this->logger->emergency("Crashed while crashing, killing process");
         @kill(getmypid());
     }
 }
All Usage Examples Of pocketmine\scheduler\ServerScheduler::cancelAllTasks