Async and await in loops
Basic async and await is simple. Things get a bit more complicated when you try to use await in loops.
In this article, I want to share some gotchas to watch out for if you intend to use await in loops.
Here’s the article. Enjoy!
https://zellwk.com/blog/async-await-in-loops
Key takeaways in this article:
- If you want to execute
awaitcalls in series, use a for-loop (or any loop without a callback). - Don’t ever use
awaitwithforEach. Use a for-loop (or any loop without a callback) instead. - Don’t
awaitinsidefilterandreduce. Alwaysawaitan array of promises withmap, thenfilterorreduceaccordingly.
Stay awesome,
Zell