[英]nodejs and async.waterfall with if conditions and conditional function list.
I have been working with async.waterfall and nodejs. 我一直在使用async.waterfall和nodejs。 Its working very well but now I have a question about flow. 它工作得很好,但现在我对流量有疑问。
I want to use a simple if condition in async.waterfall flow. 我想在async.waterfall流程中使用简单的if条件。
async.waterfall([
callOne,
callTwo,
if(condition > 0 ) {
callTest1,
callTest2,
}else{
callTest3,
callTest4,
}
callThree,
callFour,
callFive,
], function (err, result) {
if (err) {
return res.status(400).jsonp({error: err});
}
});
I just want to test for one condition .. 我只是想测试一个条件..
If it is condition is true 如果是条件是真的
then run a few functions 然后运行一些功能
else 其他
run other functions. 运行其他功能。
endif 万一
cleanup 清理
I was trying this too...one async.waterfall calling two async.waterfall/s 我也在尝试这个...一个async.waterfall调用两个async.waterfall / s
router.post('/testUser', function (req, res, next) {
......
function validateAccount(callback) {
if (config.CHECK_EMAIL_MEMBER_ID > 0) {
async.waterfall([
callOne,
callTwo,
if(condition > 0 ) {
callTest1,
callTest2,
}else{
callTest3,
callTest4,
}
callThree,
callFour,
callFive,
], function (err, result) {
if (err) {
return res.status(400).jsonp({error: err});
}
});
} else {
async.waterfall([
callOneb,
callTwob,
if(condition > 0 ) {
callTest1b,
callTest2b,
}else{
callTest3b,
callTest4b,
}
callThreeb,
callFourb,
callFiveb,
], function (err, result) {
if (err) {
return res.status(400).jsonp({error: err});
}
});
}
}
async.waterfall([
setupUser,
testOne,
validateAccount,
sendEmail,
], function (err, result) {
if (err) {
return res.status(400).jsonp({error: err});
}
});
});
You certainly can't use if
statements inside an array, but I think what you're looking for is this: 您当然不能在数组中使用if
语句,但我认为您正在寻找的是:
async.waterfall([
callOne,
callTwo,
function (condition, callback) {
if (condition > 0) {
async.waterfall([
callTest1,
callTest2
], callback);
} else {
async.waterfall([
callTest3,
callTest4
], callback);
}
},
callThree,
callFour,
callFive,
], function (err, result) {
if (err) {
return res.status(400).jsonp({error: err});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.