【发布时间】:2015-06-17 05:42:34
【问题描述】:
我将 Bluebird Promises 用于 Node.js 应用程序。如何为我的应用程序引入条件链分支?示例:
exports.SomeMethod = function(req, res) {
library1.step1(param)
.then(function(response) {
//foo
library2.step2(param)
.then(function(response2) { //-> value of response2 decides over a series of subsequent actions
if (response2 == "option1") {
//enter nested promise chain here?
//do().then().then() ...
}
if (response2 == "option2") {
//enter different nested promise chain here?
//do().then().then() ...
}
[...]
}).catch(function(e) {
//foo
});
});
};
除了还没有找到一个可行的版本之外,这个解决方案在某种程度上感觉(和看起来)很奇怪。我偷偷怀疑我在某种程度上违反了承诺或类似的概念。还有其他关于如何引入这种条件分支的建议(每个步骤都不是一个而是多个后续步骤)?
【问题讨论】:
-
另见nested 和conditional 链
标签: javascript promise bluebird