pocketmine\scheduler\AsyncPool::collectTasks PHP Метод

collectTasks() публичный Метод

public collectTasks ( )
    public function collectTasks()
    {
        Timings::$schedulerAsyncTimer->startTiming();
        foreach ($this->tasks as $task) {
            if ($task->isFinished() and !$task->isRunning() and !$task->isCrashed()) {
                if (!$task->hasCancelledRun()) {
                    $task->onCompletion($this->server);
                }
                $this->removeTask($task);
            } elseif ($task->isTerminated() or $task->isCrashed()) {
                $this->server->getLogger()->critical("Could not execute asynchronous task " . (new \ReflectionClass($task))->getShortName() . ": Task crashed");
                $this->removeTask($task, true);
            }
        }
        Timings::$schedulerAsyncTimer->stopTiming();
    }

Usage Example

Пример #1
0
 /**
  * @param int $currentTick
  */
 public function mainThreadHeartbeat($currentTick)
 {
     $this->currentTick = $currentTick;
     while ($this->isReady($this->currentTick)) {
         /** @var TaskHandler $task */
         $task = $this->queue->extract();
         if ($task->isCancelled()) {
             unset($this->tasks[$task->getTaskId()]);
             continue;
         } else {
             $task->timings->startTiming();
             try {
                 $task->run($this->currentTick);
             } catch (\Throwable $e) {
                 Server::getInstance()->getLogger()->critical("Could not execute task " . $task->getTaskName() . ": " . $e->getMessage());
                 Server::getInstance()->getLogger()->logException($e);
             }
             $task->timings->stopTiming();
         }
         if ($task->isRepeating()) {
             $task->setNextRun($this->currentTick + $task->getPeriod());
             $this->queue->insert($task, $this->currentTick + $task->getPeriod());
         } else {
             $task->remove();
             unset($this->tasks[$task->getTaskId()]);
         }
     }
     $this->asyncPool->collectTasks();
 }