Callback pyramid even with a promise

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?

+4
source share
1 answer

What about

taskA()
   .then(taskB)
   .then(taskC)
   .then(function(){});
+4
source

Source: https://habr.com/ru/post/1535610/


All Articles