/** * @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(); $task->run($this->currentTick); $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()]); } } if ($this->asyncTasks > 0) { //Garbage collector $this->asyncPool->collect([$this, "collectAsyncTask"]); foreach ($this->asyncTaskStorage as $asyncTask) { if ($asyncTask->isFinished() and !$asyncTask->isCompleted()) { $this->collectAsyncTask($asyncTask); } } } }
/** * @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(); }
/** * @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 (\Exception $e) { Server::getInstance()->getLogger()->critical("Could not execute task " . $task->getTaskName() . ": " . $e->getMessage()); if (($logger = Server::getInstance()->getLogger()) instanceof MainLogger) { $logger->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()]); } } if ($this->asyncTasks > 0) { //Garbage collector $this->asyncPool->collect([$this, "collectAsyncTask"]); if ($this->asyncTasks > 0) { foreach ($this->asyncTaskStorage as $asyncTask) { $this->collectAsyncTask($asyncTask); } } } }