Async.而 async.而 在 async.series 中
Async.whilst inside async.series
我在async.whilst
内部使用async.waterfall
,在async.series
里面像这样(它只崩溃一次,但随后继续保持应有的状态):
function(callback){
async.whilst(
function() {
console.log("Number of things left: " + classes.length); return classes.length > 0;
},
function(innerCallback){
//Define some variables.
async.waterfall([
function (next) {
MyTable.find({ Data: theData},{ DataThis:1, Stuff:1, _id:0 },next).limit(1);
},
function (results, next) {
if(results.length > 0 && results[0].theData=== parseInt(theInfo)){
//Update my database
} else{
next();
}
}
], setTimeout(function() {
//Splice the data. I.e. mydata.splice(i-1,1);
innerCallback();
}, 0)); //closing async.waterfall.
},
function(err){
// The final function of whilst
callback(err);
}) // Whilst finished
}
但是我得到一个错误:
serverClasses2-3 TypeError: undefined is not a function
serverClasses2-3 at /home/node_modules/async/lib/async.js:52:16
serverClasses2-3 at /home/node_modules/async/lib/async.js:1204:30
serverClasses2-3 at /home/routes/indexClasses2.js:267:11
serverClasses2-3 at Query.callback (/home/node_modules/mongoose/lib/query.js:2021:7)
serverClasses2-3 at /home/node_modules/mongoose/node_modules/kareem/index.js:177:19
serverClasses2-3 at /home/node_modules/mongoose/node_modules/kareem/index.js:109:16
serverClasses2-3 at process._tickDomainCallback (node.js:381:11)
有没有人遇到过同样的错误?
您将setTimeout(…, 0)
的结果作为回调传递给async.waterfall
。它不应该是undefined
,而是一个计时器对象,但它仍然不可调用,并且会抛出这样的错误。
相反,只需直接传递回调:
async.waterfall([…], innerCallback)
或者,如果需要执行更多操作,请在超时时使用函数表达式。
相关文章:
- node.js,async,restify:无法使restify调用在async.series内同步
- 如何防止bind在使用async.series时更改node.js中的原始对象
- 使用预定义函数的NodeJS async.series
- Node js async.series无法使用Express应用程序--响应发生得太早
- 等待函数结束(在 async.series 中)无法按预期工作
- 如何等待findOneAndUpdate完成,然后再继续async.series
- 为什么 async.series 只产生一个输出
- Node.js: forEach inside async.series
- 使用从 async.series 调用的原型函数中的“this”
- Async.而 async.而 在 async.series 中
- Async.series 不适用于 fs.readFile
- async.applyEachSeries无法引用'这'与async.series不同
- async.waterfall和async.series之间有什么区别
- 如何使用async.series来等待响应
- 结合异步.Each和async.series
- 用async.series的回调函数填充数组
- async.series和async.each未按预期工作
- rs.readFile in async.series 排序问题
- 异步 grunt 任务中的 async.series
- 如何在async.series中使用mocha测试