I suggest adding a manual tick() call to the loop:
interface LoopInterface
{
// ...publicfunctiontick(): void;
}In this case, the implementation of the run() method will be as follows:
publicfunctionrun()
{
$this->running = true;
while ($this->running) {
$this->tick();
}
} Such functionality is extremely necessary if the implementation uses its own event loop.
Such cases are needed when you need to implement additional functionality, for example, add support for high-performance tick handlers. For example:
class MyLoop
{
publicfunction__construct(LoopInterface$parent) { ... }
publicfunctionrun(): void
{
while(true) {
$now = \microtime(true);
$delta = $now - $this->updated;
// custom operationsforeach ($this->ticksas$handler) {
$handler($delta);
}
$this->parent->tick();
$this->updated = $now;
}
} }
I suggest adding a manual
tick()call to the loop:In this case, the implementation of the
run()method will be as follows:Such functionality is extremely necessary if the implementation uses its own event loop.
Such cases are needed when you need to implement additional functionality, for example, add support for high-performance tick handlers. For example: