router.get('/linktestrange', function(req, res, next) {
var idarrays = [];
for (var id = req.query.creative_id_min; id <= req.query.creative_id_max; id++) {
idarrays.push(id);
}
async.mapSeries(idarrays, function(id, callback) {
querydata.creative_id = '' + id;
debugasync("sync map debug : ", querydata);
linktestbyid(querydata, queryday, (rs) => {
debugasync("debug async rs : ", rs);
callback(rs);
})
}, (rs) => {
debug("all async rs : ", rs);
res.send(rs);
});
});
注意: callback(rs); 这样导致 async.mapSeries 只对 idarrays遍历了第一个值就结束了。
正确地写法是下面的,callback函数必须有两个参数:
callback(null,rs);
(err,rs) => {
debug("all async rs : ", rs);
res.send(rs);
网友评论