Interval duration in ms, defaults to 1000
Starttime of when the timer starts, used for the accuracy calculation
Id returned by setTimer, used to stop the timer
The amount of ticks/callbacks that has been invoked for the current instance
Resets the start time and the ticks of the timer (used for safechecking the timing accuracy), making it ready for another start().
Starts the timer, invoking the callback
The callback to invoke
Stops the timer by clearing the current timerId for the setTimer
Generated using TypeDoc
A more accurate timer than setInterval. Requires a callback but works as a class instead of a function, and provides functions for start and stop.
The timer works with setTimer instead of setInterval, safechecking the amount of time that SHOULD have passed since the start of the timer and takes that difference into account for setTimer. That means that you can be sure that with an input of 1000ms, after 10 minutes the callback function has been called 600 times.
myTimer = new Timer(() => console.log('One seconds passed!', 1000)); myTimer.stop();