Suppose we need to perform some I/O on items of an array, like fetching the owners of cats from the cats' IDs using some API.
const catIDs = [13...
For further actions, you may consider blocking this person and/or reporting abuse
Calling this an oopsie or an error is a bit unfortunate.
Sometimes you want to make requests serially. This is not a mistake.
Maybe you want to fail or interrupt the whole process based on the result of one of the fetches. You can do that easily in a for loop.
Consider if you had 100 fetches to do - you don't want to fire them all off simultaneously and flood the services you're using. You could take serial chunks of the work in a for loop and fire those off in parallel.
So, good tip with map & Promise.all, but serial execution is not a mistake in and of itself
Thank you for this comment. I should have stated that this is only something people should be aware of. I went with a clickbaity title just to get it out there. I'll update the article to include this.
I was wandering on social media when this article poped up. But had no time to finish this off, therefore this page was opened for about 3 weeks long and now I had the time. I finished it! I don't regret! Very useful article (boomerangs, right? :)). Thank you your effort!
Thank you for your support!
I've always had some trouble with async/await, some unexpected stuff always happened when using them with map/filter/reduce.
Found some solutions but this is by far the most instructive. Great examples and great first post!
Thank you! It feels great to hear from someone who found the post helpful
hey Neil, great article, can you recommend me a good best practice article or books about something like this and to learning the mern stack thank you
Thank you! I haven't worked on JS in a while now, so I don't recall any best practice article or books at the moment. But I did learn a lot from Eloquent JavaScript and Andrew Mead's Udemy courses
thanks bud, hope that you find your true life purpose as a good and be better human being.. always remember allah, buddy.
Thanks for the tip. Could you have used generators, instead, to do the job?
Async await are based on generators but I haven't used generators themselves as they're not as popular as async await. It would be very interesting to see how generators would be used for async code
Good tip! Congratulations on your first post!
Thank you!
Oh man. This is some good stuff. I feel like I'm a serial async/await abuser.
Great post. Really interesting to read this approach to async/await and getting code running in parallel. This helps solidify the power of an async/await approach to this kind of process.