Closed
Description
I suggest adding a manual tick()
call to the loop:
interface LoopInterface
{
// ...
public function tick(): void;
}
In this case, the implementation of the run()
method will be as follows:
public function run()
{
$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
{
public function __construct(LoopInterface $parent) { ... }
public function run(): void
{
while(true) {
$now = \microtime(true);
$delta = $now - $this->updated;
// custom operations
foreach ($this->ticks as $handler) {
$handler($delta);
}
$this->parent->tick();
$this->updated = $now;
}
}
}
Metadata
Metadata
Assignees
Labels
No labels