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.
Properties
Section titled “Properties”repeats
Section titled “repeats”Whether the timer should repeat.
repeats: boolA repeating timer will keep firing until it is invalidated. In contrast to non-repeating timers, repeating timers are not automatically invalidated. Defaults to false.
timeInterval
Section titled “timeInterval”The frequency at which the timer fires, in milliseconds.
timeInterval: numberBe aware that the time interval is specified in setting. Defaults to 0, causing the timer to fire instantly.
Methods
Section titled “Methods”
new Timer()
Section titled “new Timer()”Constructs a timer.
new Timer()Constructs a timer that fires after a specified time interval.
invalidate()
Section titled “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(callback)
Section titled “schedule(callback)”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
Section titled “Parameters”callback fn()
The callback to be called when the timer fires.
schedule(timeInterval, repeats, callback)
Section titled “schedule(timeInterval, repeats, callback)”Schedules a timer.
static schedule(timeInterval: number, repeats: bool, callback: fn()): TimerThis is a convenience function for creating a new timer. The created timer is instantly scheduled and will fire after the specified time interval.
Parameters
Section titled “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 be called when the timer fires.
Return value
Section titled “Return value”Timer
The constructed timer.