Javascript - Asynchrony

About

Asynchronous in javascript.

Asynchrony is not only critical to the performance of our applications, it’s increasingly becoming the critical factor in writability and maintainability.

Method:

Fetch operations are asynchronous by nature and returns generally a promise. See Browser - Ajax (Asynchronous JavaScript And XML).

Method

Callback

callbacks is the primary method of enabling asynchrony.

Callback pyramid of doom

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises
doSomething(function(result) {
  doSomethingElse(result, function(newResult) {
    doThirdThing(newResult, function(finalResult) {
      console.log('Got the final result: ' + finalResult);
    }, failureCallback);
  }, failureCallback);
}, failureCallback);

getData( a => {
     getMoreData(a, b => {
         getMoreData(b, c => {
             getMoreData(c, d => {
                 getMoreData(d, e => {
                     console.log(e);
                 }
             }
         }
     }
}

Promise

Documentation / Reference


Powered by ComboStrap