Understand Promise in 5 minutes
Synchrounous and asynchrounous requests
A process need to wait for another process got finished and then does something else in synchrounous model; in contract, asynchrounous one does not. ( It will describe with sync and async below.)
Sample for async functions
- how to handle the result of each async processes below??
- how does our system know the async process is done??
To handle async processes
Method 1: Callback function // ES4 standard
Real example 1: XMLHttpRequest ES5 standard
Method 2: Promise ES6 standard
An object to wrap and unwrap objects and functions asynchronously
Real example 2a: jQuery
Real example 2b: Fetch HTML5 standard
Method 3: async/await ES7 candidate
Because sending requests asynchrounously is hard for developers to handle their responses. Using these new methods could be easier to take asynchrounous functions sequentially like accessing synchrounous functions.
Please be aware that Promise.all() does not guarantee all requests in a sequence but for the resolved result; besides, if a process got failed, Promise.all() would only get error catch