简体   繁体   English

仅通过一个回调并行运行异步

[英]Run async in parallel with only one callback

I have a question which might be silly. 我有一个可能很愚蠢的问题。 Correct me if I'm wrong. 如果我错了纠正我。

I'm gettin 1 000 results from REST endpoint. 我从REST端点获得了1000条结果。 However the results are tokenized and split into 100 element arrays. 但是,将结果标记化并分成100个元素数组。 After I process 100 elements I need a callback to get next 100. 处理完100个元素后,我需要回调以获取下一个100。

Below is my code for running through array 下面是我通过数组运行的代码

  async.eachSeries(body.hits.hits, function(hit, loopHit) {
      check_order(hit, loopHit);
  }, function done() {
      // get next array
  });

The reason reason I do async here is because I need to know when I complete all 100 results (function done). 我在此处执行异步操作的原因是,我需要知道何时完成所有100个结果(函数已完成)。

The result is - I need to run all 100 elements one by one (in check_order I connect to different REST point and wait for callback there), and I would like to run on all of them simultaneously, and once the last is completed I would like to get next array from first endpoint. 结果是-我需要一个接一个地运行所有100个元素(在check_order中,我连接到不同的REST点并等待在那里的回调),我想同时在所有这些元素上运行,一旦最后一个完成,我将想从第一个端点获取下一个数组。

Any ideas? 有任何想法吗?

Your callback is missing in the async: 您的回调在异步中丢失了:

  async.eachSeries(body.hits.hits, function(hit, loopHit) {
      check_order(hit);
      loopHit();
  }, function done() {
      // get next array
  });

And also you are giving the callback loopHit in the checkHit function. 另外,您还要在checkHit函数中提供回调loopHit。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM