async.times(以更好的方式处理循环)

要在 node.js 中的循环内执行函数,可以使用 for 循环进行短循环。但循环很长,使用 for 循环会增加处理时间,这可能导致节点进程挂起。在这种情况下,你可以使用: asycn.times

function recursiveAction(n, callback)
{
    //do whatever want to do repeatedly
    callback(err, result);
}
async.times(5, function(n, next) {
    recursiveAction(n, function(err, result) {
        next(err, result);
    });
}, function(err, results) {
    // we should now have 5 result
});

这是并行调用的。当我们想一次调用一个时,请使用: async.timesSeries