title: setTimeout timing precision
body: <p>I saw there are a lot of posts about this function, but none really tackles this issue: how can I ensure that a setTimeout is run <em>exactly</em> and precise after those milliseconds? I am writing an application where precision is critical, and I read in many places, for example <a href="https://stackoverflow.com/questions/22154129/javascript-settimeout-loops">here</a>, which considers my same issue, that</p>
  
  <blockquote>
    <p>The problem with setInterval() and setTimeout() is that there is no
    guarantee your code will run in the specified time.</p>
  </blockquote>
  
  <p>so, is there any way to force it to run to the millisecond precision? My application is actually of the same type as the one in the topic I linked.</p>
  
  <p>I already run many timeouts in a loop (I first create an array which run the timeouts one after the other) and after a while the system gets out of sync.</p>
  
  <p>A second question, maybe: if not javascript, is there any other thing that might help with this? Maybe going for WebGL? Or is there some js library already considering/solving this?</p>
  
  <p>EDIT: I considered using requestAnimationFrame, but the intervals might be very different in timing and I read that this function was made for constant steps.</p>
  
  <p>EDIT2: I found a good algorithm on <a href="https://www.html5rocks.com/en/tutorials/audio/scheduling/" rel="nofollow noreferrer">this</a> page, which is the best I could find until now.</p>