Skip to main content

Timer

A Timer class that can start and stop timers using a unique key. All instances of Timer are stored in a static Map.

Parameters​

ParameterTypeOptionalDefaultDescription
callbackFunctionfalseThe function to call when the timer ends.
durationnumbertrue0The duration of the timer in milliseconds.
_initbooleantruetrueStarts the timer and sets up the callback to be called when the timer ends.
keystringtruerandomKeyThe unique key for this timer.

Properties​

duration​

The duration of the timer in milliseconds.

Type: number

key​

The unique key for this timer.

Type: string

isStarted​

A boolean indicating whether the timer has started.

Type: boolean

startedAt​

The timestamp when the timer was started.

Type: number

_init​

Starts the timer and sets up the callback to be called when the timer ends.

Type: boolean

Methods​

_init()​

Starts the timer and sets up the callback to be called when the timer ends.

Returns: Timer | false

kill()​

Stops the timer and removes it from the Map.

Returns: boolean