title: How to handle user input events while running long javascript code?
body: <p>I have a long running javascript code that process some kind of render (webgl).
  It's some kind of "adaptative rendering" in which i calculate a surface more and more precisely over time (meaning that the "resolution" of the scene becomes more and more precise).</p>
  
  <p>I want it to run as long as the user doesn't press a key, or move the mouse.
  As stated <a href="https://stackoverflow.com/questions/672732/prevent-long-running-javascript-from-locking-up-browser">here</a>, i could use setTimeout or setInterval, to give some time to javascript to process other events.</p>
  
  <p>I've tested setTimeout and setInterval delays on this <a href="http://jsfiddle.net/uLVD6/" rel="nofollow noreferrer">jsFiddle</a>, and i observe the following result:</p>
  
  <pre><code>setTimeout delay: 15-20 ms
  setInterval delay: 2-4 ms
  </code></pre>
  
  <p>It's fast, but still quite hard to use in my situation. I need to be able to react, finish some computations and render in <strong>16 ms</strong> to give the user the impression to run at <strong>60 fps</strong>. </p>
  
  <p>So here's the question(s):</p>
  
  <p>1) Is there some other (more clever) way to check if there are some incoming user input events to be processed ?</p>
  
  <p>2) Is there something else i can use to make some "long running code interruptible by user" ? (maybe web workers ?)</p>