3 ms·
I thought await in loops was a big no no, unless it has changed since I last checked? Doesn’t it remove any opportunity for parallelism, making the loop take m
by ElFitz 5y ago
I thought await in loops was a big no no, unless it has changed since I last checked?
Doesn’t it remove any opportunity for parallelism, making the loop take much longer than it would with a Promise.all?
Or am I missing something?
- yourad_io 5y agoSometimes you want to do things sequentially, so for..of x { await } is the way to go If you want parallelism: await Promise.all(x.map(...))
- madeofpalk 5y agoYou're right(ish) - the async functions would not run in parallel. But sometimes that's either fine, or I don't want them to run in parallel.
- ElFitz 5y agoIt’s funny; I never thought of it as a desirable behaviour. To each their own!