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.)


image source

Concept of async programming

Sample for async functions

Non-blocking environment

  • how to handle the result of each async processes below??
  • how does our system know the async process is done?? Async requests(1).png

To handle async processes

what is ES6, ES7, ECMAScript2015...

Method 1: Callback function // ES4 standard

what is Callback hell

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

For unwrap Promise object easily


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