title: Is there a Javascript instruction to avoid async callback hell?
body: <p>Is there a Javascript instruction to avoid the async callback hell?
  Similar to "if then else" I imagine a "do then".
  Example, suppose asyncFunc1(cb, errCb) is an async function that calls cb() on success and errCb() on failure. The same for asyncFunc2, asyncFunc3, etc. With a proper async instruction I imagine to do something like:</p>
  
  <pre><code>do (asyncFunc1) {
  
      // error code for failure of asyncFunc1 goes here
  
  } then (asyncFunc2) {
  
      // error code for failure of asyncFunc2 goes here
  
  } then (asyncFunc3) {
  
      // error code for failure of asyncFunc3 goes here
  
  } // etc...
  
  var a=Math.abs(-1); // first synchronous code. This, and all the
  // following code, is executed at the  same time of
  // the "do (asyncFunc1) { } then ... {}" block
  </code></pre>
  
  <p>asyncFunc1 is called when "do (asyncFunc1)" is executed, on error the code inside the brackets is executed, on success "asyncFunc2" is executed. Then again, on error the code inside the bracket is executed, on success "asyncFunc3" is executed. All this is executed at the same time of "var a=Math.abs(-1);" and of all its successive code.</p>
  
  <p>Promises already are near, but, this would be cleaner: no need to define new functions and no pyramid shape.</p>
  
  <p>Note1: the above example is the same as:</p>
  
  <pre><code>asyncFunc1(
      function() {
  
          asyncFunc2(
              function() {
  
                  asyncFunc3(
  
                      // etc...
  
                          function() {
  
                              var a=Math.abs(-1); // first call of a synchronous function here
  
                          },
                          function() {
                              // error code for failure of asyncFunc3 goes here
                          }
                  )
  
              }, 
              function() {
  
                  // error code for failure of asyncFunc2 goes here
              }
         )
  
      },
      function() {
  
          // error code for failure of asyncFunc1 goes here
      }
  )
  </code></pre>
  
  <p>Note2: if asyncFunc1 has arguments arg1, arg2, ... one would do:</p>
  
  <pre><code>do(asyncFunc1, arg1, arg2, ...) { }
  </code></pre>