3 ms·
> Promise.all will start all the promises so they run in parallel, while `for-of-await` executes them in series. Not true. Promises represents computation that
by hdhzy 9y ago
> Promise.all will start all the promises so they run in parallel, while `for-of-await` executes them in series.
Not true. Promises represents computation that is already started so both Promise.all and for-of will result in the same parallel computation. Promise.all does not start anything (except the promise that waits for other promises). The difference is only when you create a promise. If you do so inside for-of loop with inner awaits then it is sequential (because next promise is created only when the previous one is resolved).
The code example in the article shows inner await in for-of loop with getItem: it's the function call inside for-of-await that makes it sequential, not the loop itself. If they first made all calls to getItem, gathered results (promises) in an array and then made a for-of loop with awaits of that array elements then it'd be parallel.