I've gone thorough 20-30 videos on async await in the last few days as I am trying to learn JavaScript and Node.js - and hands down this is the best that I've seen for a beginner to learn the concept and build upon it.
the reason i like Traversy Media is because you actually start with him like you write all the functions together you create files together, these ones with pre-existing code is not as fun, but its a cool video anyways, thanks
Thanks for watching! 🙂 Async really is amazing, best thing that has happened to Node.js (well Promises first and foremost, but then Async/Await as it's a wrapper more or less).
Hey CodeWorkr . Amazing video. a new subscriber to your channel . Also your accent is not bad . In fact it is very good to understand and the examples you provide is very simple and clean . please do keep it up . Expecting more videos from you on tricky concepts. 👏👏👏
Excellent video! Very well prepared and demonstrated. The little hint about async/await not working with functions using a callback themselves was awesome. That was my main point, why I still struggled. Thanks a lot!
the only useful thing in the video is the promise all function, that actually shows performance benefit. what's the point of using async/await sequencially? take note that it can even degrade performace running sequencially because of the extra overhead.
Hey Yan! There are situations where you need to do 2 "slow" operations in sequence, where the latter operation depends on the data returned by the former operation. In that situation you'd actually use async/await in sequence and won't use Promise.all(). An example: // Get some data from the DB const data = await grabDataFromDB({ id: 'something' }) // Process said data const processedData = await processData(data) You can't really use Promise.all() here as second line depends on the results of first line.
@@CodeWorkr In the examples you provide in your reply and video there is no preference to async/await over sync ops. the whole purpose of async ops is that you can keep running in the background with other stuff or in parallel. if you don't do that, than there is no point using async await in the first place.
@@yanpelov Oh, understand what you mean now - yes, we agree on that, await-ing multiple things in sequence is making the entire flow sequential and there aren't advantages (as when using promise.all). Still, you might be using async/await throughout your project and for example a single function might make a use of both promise.all() (where applicable) and then awaiting operations in sequence where absolutely necessary, so you're still saving time/performance when you can (on promise.all() part) and then doing few things sequentially when you can't get away of doing so. // Some time will be saved because we're not sequentially calling all of them const data = await Promise.all([getData01(), getData02(), getData03()]) // (In between) Some time will be lost because of waiting on upper promise // Some time will be saved because we're not sequentially calling all of them const results = await Promise.all([processData(data[0]), processData(data[1]), processData(data[2])]) That'd be a combination of both "patterns" for example. Of course correct me if you think I'm wrong
@@CodeWorkr btw, consider the following real life example to demonstrate the usefulness of asynchrony in life (pseudo code) : async lifeExample() { prepareSoup() ready = await putSoupOnStove() //takes about 30 minutes to cook do { runOnTreadMillFor10Min() //do workout while soup is cookin' } while (!ready) //open pot lid and check if soup is ready eatSoup() //eat the soup now that it's ready shower() //after you worked out for ~30 mins and ate soup. watchNetflix() //enjoy your evening }