Skip to content

Manual "tick" execution #216

Closed
Closed
@SerafimArts

Description

@SerafimArts

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions