Combining Async Await with Promises
Вставка
- Опубліковано 15 вер 2024
- Async and await can be combined and used with Promises but the results may sometimes be surprising.
This video looks at how you can effectively combine Async, await, and Promises.
It is important to remember that fetch( ) calls are also Promises.
Code GIST: gist.github.co...
Simple & Clean === Quality === True (I speak JS 😇🤐) , Distributing knowledge is one of the best gifts and thing one can do. Thank You for teaching me these concepts
Thank you for another wonderful lesson. Many teacher just make this kind thing like a format, you are the first to explain what is happening inside and where the error comes from. Simply great.
Thanks for taking the time and making this awesome content, and making javascript wonderful to understand.
Another very cool tutorial!
Thank you for helpful contents! Someday please make a video introducing your development environment for the beginners :)
I make my videos using Brackets with the Emmets plugin. I have videos on both already. I demo most things in either Chrome or in the Terminal (Command Prompt). For things that require a web server, I use MAMP. I have a number of videos about aspects of MAMP too. Just do a search on my channel home page for "Brackets" and "Emmet" to start.
Interesting! Now I try to see how use asyn await and promise all together
So the main difference with regular Promise is that here we get the value of the promise and we don't need to use then?
Also if I remove async and await and reject the promise in the delay function, when I log the Promise I get [[PromiseStatus]]: "resolved" - isn't that supposed to be rejected? Thank you
Effectively yes, we are removing the requirement for the then( ) by adding await.
At 3:15 in the video you can see the delay function run without the await and it will contain Promise pending. ~1000ms later it will show rejected.
@@SteveGriffith-Prof3ssorSt3v3 Ok, I got it correctly. Thank you for your response!
Thanks great videos.
Very Informative and great detailed oriented videos.
can you suggest best resources to learn JS ?
There are lots of great resources online. On UA-cam Wes Bos, Brad Traversy, and Colt Steele are all really good.
❤
why resolved promise has printed 42 at the end of the video? We passed ms as 1000 right?
1000ms is the delay before the function resolve gets called. 42 is the value passed to the function resolve.