Skip to content

Timer

A timer that fires after a time interval has elapsed.

The timer fires after a specified time interval has elapsed. The timer can be repeating in which case it will fire multiple times.

Whether the timer should repeat.

repeats: bool

A repeating timer will keep firing until it is invalidated. In contrast to non-repeating timers, repeating timers are not automatically invalidated. Defaults to false.

The frequency at which the timer fires, in milliseconds.

timeInterval: number

Be aware that the time interval is specified in setting. Defaults to 0, causing the timer to fire instantly.

Constructs a timer.

new Timer()

Constructs a timer that fires after a specified time interval.

Stops the timer from firing.

invalidate()

Stops the timer from firing ever again. Non-repeating timers are automatically invalidated after they have fired once. Repeating timers must be manually invalidated.

Schedules the timer.

schedule(callback: fn())

Schedules the timer using its configuration. The supplied function is called when the timer fires. To stop the timer from firing, call the invalidate() function.

callback fn()

The callback to be called when the timer fires.

Schedules a timer.

static schedule(timeInterval: number, repeats: bool, callback: fn()): Timer

This is a convenience function for creating a new timer. The created timer is instantly scheduled and will fire after the specified time interval.

timeInterval number

The time interval to fire the timer at.

repeats bool

Whether the timer should repeat or not.

callback fn()

The callback to be called when the timer fires.

Timer

The constructed timer.