/**
* @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);
}
}
}
}