Skip to content

Instantly share code, notes, and snippets.

@badsyntax
Created February 19, 2015 09:18
Show Gist options
  • Select an option

  • Save badsyntax/fc2c4778b92dce3afc2f to your computer and use it in GitHub Desktop.

Select an option

Save badsyntax/fc2c4778b92dce3afc2f to your computer and use it in GitHub Desktop.
A reminder about how to use async.js series functions
// This will exit with the following error message: "RangeError: Maximum call stack size exceeded"
var async = require('async');
var c = 0;
async.eachSeries(new Array(5000),
function process(item, next) {
console.log(++c);
next();
},
function onDone() {
console.log('Done');
}
);
// Using setImmediate we resolve the problem, as the iterator has to be async
// See: https://github.com/caolan/async/issues/267#issuecomment-14782072
var async = require('async');
var c = 0;
async.eachSeries(new Array(5000),
function process(item, next) {
console.log(++c);
setImmediate(next);
},
function onDone() {
console.log('Done');
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment