Skip to main content

Timer Class

import { Timer } from "//packages.education/agent";

Constructor​

new Timer(tickFunction: function, tickInterval: number)​

Creates a new Timer that can run the specified tickFunction every tickInterval milliseconds.

Example​

function step() { /* ... */ }

const timer = new Timer(step, 100);

Properties​

timer.tickFunction: function​

The function the Timer runs.

timer.tickInterval: number​

The interval in milliseconds to run the tickFunction.
Default: 100

timer.tickCount: number read-only​

The number of runs the tickFunction since the creation of the Timer.

timer.isRunning: boolean read-only​

Tells whether the Timer is currently running or not.

Methods​

timer.tick()​

Runs the specified tickFunction once.

timer.resetTicks()​

Resets the tickCount to 0.

timer.start()​

Starts the Timer.

timer.stop()​

Stops the Timer.

timer.toggle()​

Toggles the Timer. Stops if running, starts if not.