javascript – async.each和async.eachSeries之间的区别

前端之家收集整理的这篇文章主要介绍了javascript – async.each和async.eachSeries之间的区别前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
async.each是作为异步数组迭代工作的吗?

async.eachSeries是否作为同步数组迭代工作?(它实际上等待响应)

我问这些是因为它们都有回调但async.each就像异步数组迭代一样对ex:

//This is traditional way to iterate an array with callback functions in node.js
//Is this same with async.each ? i want to know it actually.

for (var i = 0; i < data.length; i++) {
 (function (i) {
  request(data[i],function(body){
   console.log(body)
  });
 })(i);

//if this codes and async.each are doing same things,//i know that async gives me an aert when all finished thats the difference.

解决方法

您的代码示例与async.each的作用最相似,因为所有异步请求调用都是立即生成的,并允许并行执行.

与async.eachSeries的区别在于,每次迭代都会等待异步操作完成,然后再开始下一次操作.

猜你在找的JavaScript相关文章