async.each和async.eachSeries之间的区别 [英] Difference between async.each and async.eachSeries

查看:632
本文介绍了async.each和async.eachSeries之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

async.each 作为异步数组迭代工作吗?

Is async.each working as asynchronous array iterating?

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

Is async.eachSeries working as synchronous array iterating?(it waits response actually)

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

I'm asking these because both have callbacks but async.each works like asynchronous array iterating for 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.


推荐答案

您的代码示例与<$ c最相似$ c> async.each 确实如此,因为所有异步请求一次调用并允许并行执行。

Your code example is most similar to what async.each does, as all the async request calls are made at once and allowed to proceed in parallel.

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

The difference with async.eachSeries is that each iteration will wait for the async operation to complete before starting the next one.

这篇关于async.each和async.eachSeries之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆