Q和承诺链接

Flo*_*vre 0 chaining node.js promise q

假设A()返回已解析的promise并转到B().但是,在某些情况下,我需要B()完成而不执行next then()(我不想进入C().我可以在B()方法中使用defered.reject()但它确实如此似乎不对.

var p = pull(target)
.then(function (data) {
    return A();
})
.then(function (data) {
    return B();
})
.then(function (data) {
    return C();
})
Run Code Online (Sandbox Code Playgroud)

任何提示?

Ben*_*aum 5

你使用promises进行分支的方法与没有它们的方式相同 - if主要是条件:

var p = pull(target)
.then(A).then(B)
.then(function (data) {
    if(data) return C(); // assuming B's resolution value is a boolean
});
Run Code Online (Sandbox Code Playgroud)