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
.
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.
Unfortunately, using async
's functions, the call stack gets consumed pretty fast, leading to RangeError: Maximum call stack size exceeded
.
Is there a way to tweak async
in order to prevent this problem? 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');
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.");
});