I have 3 functions that I want to perform one after another only when the previous function completed its task. I use the Promise library for this,
function taskA(){
var d = when.defer();
d.resolve();
return d.promise;
}
function taskB(){
var d = when.defer();
d.resolve();
return d.promise;
}
function taskC(){
var d = when.defer();
d.resolve();
return d.promise;
}
taskA().then(function(){
taskB().then(function(){
taskC().then(function(){
}); }); });
How should it be? I was impressed that I could easily avoid callbacks and its "doom pyramid" using promises, or am I using them incorrectly?
source
share