Created
February 19, 2015 09:18
-
-
Save badsyntax/fc2c4778b92dce3afc2f to your computer and use it in GitHub Desktop.
A reminder about how to use async.js series functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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'); | |
| } | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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