Created
July 11, 2014 14:14
-
-
Save Chris927/88ba412dc3e09eba4a9e to your computer and use it in GitHub Desktop.
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
| // same as previous gist, but now via 'async' library | |
| var async = require('async'); | |
| // some dummy rows | |
| var rows = []; | |
| for (var i = 0; i < 10000; i++) { | |
| rows.push("this is row " + i); | |
| } | |
| var maxRunning = 20; | |
| function callHandler(row, cb) { | |
| console.log("callHandler for row: " + row); | |
| setTimeout(function() { | |
| cb(null); | |
| }, 500 * Math.random()); | |
| } | |
| async.eachLimit(rows, maxRunning, function(row, done) { | |
| callHandler(row, function(err) { | |
| if (err) throw new Error(err); | |
| done(); | |
| }); | |
| }, function(err) { | |
| if (err) throw new Error(err); | |
| console.log('done'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment