title: How to rewrite forEach to use Promises to stop "freezing" browsers?
body: <p>I have a function, that looks like this.</p>
  
  <pre><code> function () {
        longArray.forEach( element =&gt; doSomethingResourceIntensive(element))
   }
  </code></pre>
  
  <p>Because the array is long and the function is a little resource intensive, it freezes the browser.</p>
  
  <p>Now I want to rewrite it using Promises, so it does the same thing, just not freezing the browser, and I want the solution to be elegant and "ES6-y"; ideally, the function would return Promise when all the iterations finished.</p>
  
  <p>I found <a href="https://stackoverflow.com/questions/714942/how-to-stop-intense-javascript-loop-from-freezing-the-browser">this question</a>, where it's dealt with using setTimeout, but it seems a little "un-ES6-y", and it doesn't return a Promise.</p>
  
  <p>I cannot do</p>
  
  <pre><code> function () {
        return Promise.all(longArray.map( element =&gt; 
            Promise.resolve().then(() =&gt; doSomethingResourceIntensive(element))
        )
   }
  </code></pre>
  
  <p>because I need to run the promises in succession and I am not sure if it would happen there.</p>