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!
Top comments (0)