Timer.cancel() method

Calling cancel() unschedules the current timer, ensuring it does not fire again until re-scheduled using Timer.scheduleOnce() or Timer.scheduleRepeat().

Syntax

Timer.cancel()

Parameters

This function has no parameters.

Return value

None (undefined).

Example

// A one shot timer:
> timer = new Timer(() => console.log("Fired!"));
undefined
> timer.scheduleOnce(20);
undefined
> timer.cancel();
undefined
// did not fire!

// A repeating timer:
> timer2 = new Timer(() => console.log("Repeat fire!"));
undefined
> timer2.scheduleRepeat(0.1);
undefined
Repeat fire!
Repeat fire!
Repeat fire!
> timer2.cancel()
undefined

References