title: JS - nice sleep-alike functionality
body: <p>I have a very CPU-intensive JS function that makes browsers kill it because of long no response. I want to have the function finished, and also i want to be able to use my browser in the meanwhile.</p>
  
  <p>My solution was to implement a sleep-alike functionality in my function after each iteration:</p>
  
  <pre><code>&lt;p id="debug"/&gt;
  &lt;script&gt;
      function example(i) {
              //do stuff
              if(i &lt; 100) window.setTimeout(function() {example(i+1);}, 100);
      }
  
      example(0);
  &lt;/script&gt;
  </code></pre>
  
  <p>The solution works well - but is there is any nicer way to implement this functionality? - without using the unnecessary recursion.</p>