In a browser environment, setTimeout and setInterval are not reliable for accuracy when a temporary sensitivity issue is an issue.
Recently we have been given requestAnimationFrame , which allows us to improve a bit (in terms of performance.now() and its timestamps).
In short, I decided to build a metronome in Javascript, and while it works, it is pretty inaccurate at a certain pace. While compensation for late frames allows the tempo not to reconnect over time, the individual bits are slightly muted, which does not work for the metronome. (This is not a problem for animation, because it should not be discrete in nature.)
Currently, I have the opportunity to try to perform a lookahead based on the threshold that I will indicate in order to try to place a click between the available frames (using setTimeout in the animation loop). I believe, however, that I will run into similar problems, since setTimeout not reliable in the browser due to the event loop, unless the HTML5 Audio API allows you to delay playback for a few milliseconds.
My question is: Are setTimeout and setInterval more accurate and reliable in web worker and browser environment?
source share