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
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
callback | Function | false | The function to call when the timer ends. | |
duration | number | true | 0 | The duration of the timer in milliseconds. |
_init | boolean | true | true | Starts the timer and sets up the callback to be called when the timer ends. |
key | string | true | randomKey | The 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.
kill()
Stops the timer and removes it from the Map.
Returns: boolean