|
|
|
|
|
by quantum5
1562 days ago
|
|
It's actually using setTimeout. Every time the callback fires, it calculates exactly how many milliseconds it would take before the next second arrives, and schedules another timeout exactly that many milliseconds later. This is done separately for both decimal and 24-hour time to ensure the most accurate time is shown. I believe this avoids the weird issues with setInterval but does not use as much CPU as requestAnimationFrame. |
|
I made a decimal time clock here https://github.com/wegry/decimal-time where I used `requestAnimationFrame`. Admittedly, it probably uses more CPU than it should.
I think I had an issue `setInterval` similar to https://stackoverflow.com/a/729943 talking about here
> In this Fiddle, you can clearly see that the timeout will fall behind, while the interval is almost all the time at almost 1 call/second (which the script is trying to do). If you change the speed variable at the top to something small like 20 (meaning it will try to run 50 times per second), the interval will never quite reach an average of 50 iterations per second.