4 ms·
One thing I really like async/await for is you can use them in for-loops. It makes it significantly easier to do async work in what was previously very synchron
by madeofpalk 5y ago
One thing I really like async/await for is you can use them in for-loops. It makes it significantly easier to do async work in what was previously very synchronous.
- ElFitz 5y agoI 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!