Day 43 of #100DaysOfCode: Review how to use async/await for the Promise (ES7)
Jen-Hsuan Hsieh
Posted on November 3, 2020
Introduction
Aync/await is used to resolve Promise-based objects instead of using then function
Now we try to improve the example in Day42. The left column is the traditional way to resolve the Promise object. The right column is using wait
1. Resolving a Promise object by using await
- We are only allowed to use await in async function.
- The program will proceed to next line of code after completing.
- We have to add try catch around the code to handle error.
2. Resolving multiple Promise objects at once by using await (Promise.all)
- Check the state of the Promise.all object. The result is rejected if one of resolved objects has been rejected.
3.Resolving multiple Promise objects at once in different states by using await (Promise.allSettled)
- Check the state of the Promise.all object. It will contain all results of elements
Articles
There are some of my articles. Feel free to check if you like!
💖 💪 🙅 🚩
Jen-Hsuan Hsieh
Posted on November 3, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
javascript Day 43 of #100DaysOfCode: Review how to use async/await for the Promise (ES7)
November 3, 2020