然后在promise中添加逻辑

时间:2015-12-28 09:58:43

标签: javascript promise bluebird

使用以下代码测试承诺(我使用BlueBird)并且我有一个不同的问题(代码正在运行)

假设我想从每个函数中删除console.log并且我想在then链中获取return的值并将其打印到控制台,我应该如何采用代码?

 var promise1 = function () { 
   setTimeout(function () { 
   //console.log("ret1") return "ret 1"; },
    1000);
};

var promise2 = function () {
    setTimeout(function () {
       // console.log("ret2")
        return "ret 2";
    }, 2000);
};

var promise3 = function () {
    setTimeout(function () {
        //console.log("ret3");
        return "ret 3";
    }, 1000);
    }

;

Promise.resolve()
    .then(promise1)
    .then(promise2)
    .then(promise3)

0 个答案:

没有答案