How to avoid callback crashes in the best way possible?


#1

I know this topic is been asked for so many times, most of the people recommend using the promises(but it slows down the performance), I just want to ask what is the most recommended way to handle the callbacks?? Like consider an example where I am already coming from a function which sends a callback function (I am using asycn waterfall which requires a callback )to be called when a task is completed, and the task is to fetch a record from the database.

/* fetch.js


 exports.getData = function(aeroKey,callback){
client.get(key,function(err,result,meta){   
if(err) callback(some response);    
else
    callback(some other response)   }

Let’s say I have a waterfall async like this:

/*fetchRecord.js
 async.waterfall([
 funnction(cb){
    getData(key,cb)
},
function further_Function_To_Handle_Response(){}

],function(err,res){//handle}

Now sometimes when I use this sort of technique my code crashes, some people recommended me to use promises, but is there any better and efficient way to handle crashes and maintain performance at the same time?