title: how to make a while loop really asynchronous
body: <p>I'm working on a javascript client-side project that performs some heavy computing and at the same time needs to be user friendly. This means asynchronous functions of course, but also letting the user do something while the heavy tasks are performed by the computer.</p>
  
  <p>Take this as an example of asynchronuos loop:</p>
  
  <pre><code>function async_operation(){
  
      function do_stuff(){
          var i=0;
          while(i&lt;1000000000){
              ... //do some stuff (to be more specific: localforage.setItem)
              ++i;
          }
      }
  
      setTimeout(do_stuff, 0);
  
      //do next opearions...
  }
  </code></pre>
  
  <p>This loop works perfecly and asynchronuosly, the problem is that if the user clicks on something, for example this button:</p>
  
  <pre><code>&lt;button onclick="alert('hello')"&gt;click me&lt;/button&gt;
  </code></pre>
  
  <p>the alert message pops up just after the loop has finished! So the user cannot click on anything before the function has finishes.</p>
  
  <p>Is there any way to let the user trigger some events during this task?</p>