Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use setImmediate to fix stack overflows in eachSeries. #296

Closed
wants to merge 2 commits into from

Conversation

mltucker
Copy link

async.eachSeries causes stack overflows for large lists.

process.version; // => "v0.10.4"
var async = require("async");
var _ = require("underscore");

var count = 0;
async.eachSeries(_.range(10000), function(n, callback) {
    count += n;
    callback();
}, function(err) {
    console.log(count);
});

Before:

RangeError: Maximum call stack size exceeded

After:

49995000

@diversario
Copy link

Having the same issue with stack overflow.

@boutell
Copy link
Contributor

boutell commented May 20, 2013

Whoops, I opened a duplicate issue and sent a duplicate pull request on this, so count me in as well.

@dougwilson
Copy link
Contributor

The module is meant to call async functions. Your

function(n, callback) {
    count += n;
    callback();
}

is not async, thus incompatible.

@caolan
Copy link
Owner

caolan commented Jan 23, 2014

Yes, making functions asynchronous is left up to the developer

@caolan caolan closed this Jan 23, 2014
@boutell
Copy link
Contributor

boutell commented Jan 23, 2014

OK, I understand that logic. There's a performance penalty imposed by each call to setImmediate too, so it would be redundant extra slowness for functions that are already asynchronous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants