This site is built with Viewi itself. It is experimental and still in development. If you see any bugs please do not hesitate and open an issue or DM me on Twitter.

Client Timer

use Viewi\Components\Services\ClientTimer;
class ClientTimer
    public static function setTimeoutStatic(callable $action, int $milliseconds): int;            
    public function setTimeout(callable $action, int $milliseconds): int;            
    public static function clearTimeoutStatic(int $timerId);            
    public function clearTimeout(int $timerId);            
    public static function setIntervalStatic(callable $action, int $milliseconds): int;            
    public function setInterval(callable $action, int $milliseconds): int;            
    public static function clearIntervalStatic(int $timerId);            
    public function clearInterval(int $timerId);

For example:

public function __init(ClientTimer $timer)
    // use as injected service
    $this->timer = $timer;
    $this->timerId = $timer->setInterval(fn () => $this->tick(), 1000);

public function __destroy()
    // !! Do not forget to clear interval on destroy !!

public function tick()

function postValidate()
    // use as static method
    ClientTimer::setTimeoutStatic($this->validate, 0);
    Seconds: $seconds