promise.all inside a forEach loop — everything firing at once
<p>In a Node app, I need to iterate through some items in a synchronous fashion, but some of the operations inside the loop are asynchronous. My code right now looks like so:</p>

<pre><code>someAPIpromise().then((items) =&gt; {
   items.forEach((item) =&gt; {
      Promise.all[myPromiseA(item), myPromiseB(item)]).then(() =&gt; {
         doSomethingSynchronouslyThatTakesAWhile();
      });
    }
}
</code></pre>

<p>This works wonders when the <code>items</code> is an array of 1. But, once there's more than one item, <code>promise.all()</code> will just fire off instantly for every item in the array, without waiting for the operation in the loop to end.</p>

<p>All that to say... how can I ensure that the entire operation for each item in the array is run synchronously (even if some operations are async and return a promise)?</p>

<p>Thanks so much!</p>

<p>N</p>