DEV Community

Discussion on: The dangers of async/await

Collapse
 
eugeneherasymchuk profile image
Yevhenii Herasymchuk

Here, the first 3 requests are executed in parallel, whereas the next ones rely on data fetched beforehand and will therefore be executed afterwards. Although this snippet poses a problem, did you spot it?

Poor little initBooking will have to wait for both getBasket and fetchOptions to finish before executing even though it has nothing to do with the data they'll fetch.

I didn't get the message the author wanted to bring in Unrelated code should not have to wait section. That's exactly why async/await is cool and for sure not danger.

If you want to run them in parallel - you're going with Promise.all ( of course, knowing about the first-fail behavior), you may operate each call separately as well with a personal error handling.
Don't want to say anything bad, just didn't get the info from the section

Collapse
 
christopherkade profile image
Christopher Kade

If you want to run them in parallel - you're going with Promise.all

Absolutely, if it's a habit you've developed as a developer. The point of this article being to help some beginners catch these sections that could be helped with something like Promise.all.

The example with initBooking is my abstract way of showing a bad use of a single awaited method.

Collapse
 
eugeneherasymchuk profile image
Yevhenii Herasymchuk

Agree, Christopher, thanks for the work. Actually benchmarks are awesome!
Just the title "dangers" makes it quite judging without actual arguments :)
P.S. You know how to make clickbait titles

Thread Thread
 
christopherkade profile image
Christopher Kade

I love to spook my readers first and then relieve them when they understand that it's not that big of a deal haha.

Maybe the word side-effect would have been more interesting in this case. As in the side-effect of over-using this feature.