发布于 2011-08-05 18:42:48
我也使用异步。为了帮助跟踪错误,建议你命名你的函数,而不是加载匿名函数:
async.series([
function doSomething() {...},
function doSomethingElse() {...},
function finish() {...}
]);
这样,您将在堆栈跟踪中获得更多有用的信息。
发布于 2013-03-18 18:11:21
有时很难将所有函数放在一个数组中。当你有一个对象数组,并且想要为每个对象做一些事情时,我使用类似下面的例子。
更多信息请访问:http://coppieters.blogspot.be/2013/03/iterator-for-async-nodejs-operations.html
var list = [1, 2, 3, 4, 5];
var sum = 0;
Application.each(list, function forEachNumber(done) {
sum += this;
// next statement most often called as callback in an async operation
// file, network or database stuff
done(); // pass an error if something went wrong and automatically end here
}, function whenDone(err) {
if (err)
console.log("error: " + err);
else
console.log("sum = " + sum);
});
我给这些函数命名是因为它更容易调试(也更容易阅读)
https://stackoverflow.com/questions/6954588
复制相似问题