Closed
Description
Hi,
I run in a problem with arrays that have many items.
With the following code
var a, async, i;
async = require('async');
a = (function() {
var _i, _results;
_results = [];
for (i = _i = 1; _i <= 10; i = ++_i) {
_results.push(i);
}
return _results;
})();
async.eachSeries(a, function(i, cb) {
console.log(i);
return cb();
}, function() {
return console.log('done');
});
or
async = require 'async'
a = (i for i in [1..10])
async.eachSeries a, (i, cb) ->
console.log i
cb()
, () ->
console.log 'done'
I get
…
4650
4651
4652
RangeError: Maximum call stack size exceeded```
with
async.eachSeries = function (arr, interval, iterator, callback) {
callback = callback || function () {};
if (!arr.length) {
return callback();
}
var intv = undefined;
var index = 0;
var bDone = false;
var iterate = function () {
iterator(arr[index], function(err) {
if(err) {
callback(err);
clearInterval(intv);
} else {
index++;
bDone = true;
}
});
};
intv = setInterval( function() {
if(index == arr.length && bDone) {
clearInterval(intv);
callback();
} else if(bDone) {
bDone = false;
iterate();
}
}, interval);
iterate();
};
the RangeError is fixed. But the overall call is obviously slower. But in my case this is ok, because the iterator spawns a process and have to wait anyway.
Does it makes sense to intergrate this case as a addtional function or is there a async function that does my case?
Thanks for your help.
Metadata
Metadata
Assignees
Labels
No labels