[英]is there a non-recursive feature implemented in `async`?
I need to process a quite large quantity of entries (tens of thousands) with functions such as async.each
or async.eachSeries
or async.whilst
. 我需要使用async.each
或async.eachSeries
或async.whilst
函数处理大量条目(数万个)。
Almost reduntant to say that I have to use async
because I am going to call some queries for each entry, making the code asynchronous. 几乎要说我必须使用async
因为我将为每个条目调用一些查询,从而使代码异步。
Unfortunately, using async
's functions, the call stack gets consumed pretty fast, leading to RangeError: Maximum call stack size exceeded
. 不幸的是,使用async
的函数,调用栈很快就被消耗了,从而导致RangeError: Maximum call stack size exceeded
。
Is there a way to tweak async
in order to prevent this problem? 有没有一种方法可以调整async
以避免此问题? An iterative implementation would solve the problem. 迭代实现将解决该问题。 Any alternative library that takes this problem into account? 是否有其他库考虑了此问题?
here is an example code snippet that show the problem: 这是显示问题的示例代码片段:
async = require('async'); async = require('async');
a = []
for(i = 0; i < 10000000; i++) {
a[i] = i;
}
async.eachSeries(a,function(element,callback) {
console.log(element);
callback();
},function(err){
if(err){
console.log("error:",err);
}
console.log("finished.");
});
What you are looking for is tail recursion
. 您正在寻找的是tail recursion
。 Check this question: What is tail recursion? 检查以下问题: 什么是尾递归?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.