-
Notifications
You must be signed in to change notification settings - Fork 0
How it Works
The Dev Timer Library internally uses the Date.now()
function defined by MDN:
The Date.now() static method returns the number of milliseconds elapsed since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC.
This function is used to count the time, by subtracting the end date by the begin date. That gives the time the times is running. When you stop()
the timer, the amount of time already elapsed is stored, and added to the time if you re-start()
the timer, which then gives the total time.
The events are handled differently: they are stored in an array and ordered so that the next event is the first in the array. Then, the setTimeout()
function is used to wait for the next event. The events are calculated until the end, this means that they will be synced with the end of the timer and be executed a last time when the timer ends.