0

I have the following scenario

function testing(value, callback){
    //
    service(value, function first(){
       if(value){
         service2(function second(){
           .......
           callback(null);
         });
       }else{
        service3(value, function third(){
          ......
          service4(function fourth(){
              ........
              callback(null);
          });

        });        
       }
    });
}

Now looking at the above pseudo-code snippet, we have four different async operations. If this pattern is followed readability can become or following the functional flow path becomes difficult. How can this be improved to a cleaner structure, where abstracting/decoupling the asynchronous functions can be made cleaner?

RRP
  • 2,563
  • 6
  • 29
  • 52
  • 3
    [__What is “callback hell” and how and why RX solves it?__](http://stackoverflow.com/questions/25098066/what-is-callback-hell-and-how-and-why-rx-solves-it) – Rayon Jun 08 '16 at 22:16
  • 4
    [__Aren't promises just callbacks?__](http://stackoverflow.com/questions/22539815/arent-promises-just-callbacks) – Rayon Jun 08 '16 at 22:17
  • 3
    Also, [__Avoiding Callback Hell in Node.js__](http://stackabuse.com/avoiding-callback-hell-in-node-js/) – Rayon Jun 08 '16 at 22:19
  • Check out Caolan's ASYNC.JS. Specifically, async.waterfall() – Brant Jun 08 '16 at 22:29

0 Answers0