Please take a look at this code :
function(req,res){
Article.find(id,function(err,article){
if(article.isPrivate){
//Make an async call here and do something
//I also want to execute #9 here
}
//Some task here... #9
});
}
As you can see, control flow becomes weird when you have complex conditions and async calls.
What do you recommend? Is there any way I can make async calls look like synchronous ones and have a better control flow?
Thanks for your time.
Mutyalarao
Programmer | Node.js | Learner| Doer
Hi Robert,
I was in a similar situation and I can understand how ugly the callbacks can get in JS (referred to callback hell/Pyramid of Doom).
I found using "Promises", a new concept introduced recently in Javascript, made the code much readable. Check out bluebirdjs.com library which further abstracts the Promises' boilerplate code. It would also convert the traditional code with callbacks into a Promise.
You may want to read the below: