【发布时间】:2014-03-01 03:26:53
【问题描述】:
在这个函数中:
function method2(friends, callback) {
//friends is an array of objects
var ids = _.pluck(friends, 'id'),
arrays = cut(ids, 24),
//cut() splits array into smaller arrays of given length
code = require('fs').readFileSync('...').toString();
var imp,j;
async.eachSeries(arrays, function(i, cb1) {
...
vk.request('execute', {code:code}, function(err, resp, body) {
//vk.request passes its callback to node-request module
//at this point, err is null, and body.error is undefined
if(err || body.error) return cb1(err || body.error);
var arr = body.response;
for(var e in arr) {
if(!arr[e]) return cb1();
async.eachSeries(arr[e], function(i, cb) {
...
cb();
}, cb1);
}
})
}, callback);
}
function 只被调用一次,但是 async 多次调用 callback 而不提供任何参数。我看不出任何原因。那么这段代码有什么问题呢?
【问题讨论】:
-
不知道我明白了,你真的有带回调的异步函数,还是你错误地在常规数组上使用了 async.eachSeries?
-
请修正您的代码缩进。
-
@adeneo: arrays 变量是一个常规数组
-
那你为什么要使用异步?
-
@adeneo:异步迭代这个数组
标签: javascript node.js node-async