【发布时间】:2020-04-03 09:11:31
【问题描述】:
我是 node.js 的新手,对异步有一些困惑的问题。请参阅下面的代码。
var async = require('async');
const func = function func(cb) {
cb(null, 'hello');
}
const func1 = function func1(param1, cb) {
console.log(param1);
cb(null, 'hello', 'world');
}
const func2 = function func2(param1, param2, cb) {
console.log(param1, ' ', param2);
cb(null, 'result');
}
async.waterfall([func, func1, func2], (err, result)=> {
console.log(result);
});
是的,我们知道该函数将一一运行。我的问题是,如果我有一些基于函数不同结果的复杂条件逻辑。这是否意味着我必须使用 await 并重新编写函数的返回代码?
async function doIt() {
const t= await func(parms);
... biz logic ...
const t1= await func1(t);
... biz logic ...
const t2= await func2(t1);
... biz logic ...
}
doIt();
【问题讨论】: