Timer

A timer that fires after a time interval have elapsed.

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

timeInterval

The frequency at which the timer fires, in milliseconds.

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

timeInterval: number

repeats

Whether the timer should repeat.

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.

repeats: bool

-new Timer

Constructs a timer.

new Timer()

Constructs a timer that fires after a specified time interval.


-schedule

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.

Parameters

callback
fn()
The callback to called when the timer fires.


-invalidate

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.


+schedule

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.

Parameters

timeInterval
number
The time interval to fire the timer at.

repeats
bool
Whether the timer should repeat or not.

callback
fn()
The callback to called when the timer fires.

Return value

Timer
The constructed timer.