@gamestdio/timer
Timing Events tied to @gamestdio/clock.
ClockTimer
is a subclass of Clock
, which adds methods to handle timeout and
intervals relying on Clock
's ticks.
Why?
Once built-in setTimeout
and setInterval
relies on CPU load, functions may
delay an unexpected amount of time to execute. Having it tied to a clock's time
is guaranteed to execute in a precise way.
See a quote from W3C Timers Specification:
This API does not guarantee that timers will fire exactly on schedule. Delays
due to CPU load, other tasks, etc, are to be expected.
API
Clock
setInterval(handler, time, ...args)
-> Delayed
setTimeout(handler, time, ...args)
-> Delayed
duration(ms: number)
-> Promise<void>
- Convenience method to wait for a duration in async functions or promises. See associated JSdoc for more details.clear()
- clear all intervals and timeouts, and throw any promise created with duration
.
Delayed
clear()
-> void
- Clear timeout/intervalreset()
-> void
- Reset elapsed timeactive
-> Boolean
- Is it still active?pause()
-> void
- Pause the executionresume()
-> void
- Continue the executionpaused
-> Boolean
- Is is paused?
License
MIT