Javascript - Asynchrony

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript) > ECMAScript - Grammar Standard

1 - 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 Javascript - Ajax (Asynchronous JavaScript And XML).

Advertising

3 - Method

3.1 - 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);
                 }
             }
         }
     }
}

3.2 - Promise

The promise function has two syntax:

4 - Documentation / Reference

Advertising
web/javascript/es/async.txt · Last modified: 2019/06/18 16:20 by gerardnico