Created
February 27, 2011 11:36
-
-
Save pgte/846119 to your computer and use it in GitHub Desktop.
async_function.js
This file contains 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
function async(i, callback) { | |
timeout = Math.round(Math.random() * 3000); | |
setTimeout(function() { | |
console.log(i + ' is done'); | |
callback(); | |
}, timeout); | |
} |
This file contains 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
var Step = require('step'); | |
var collection = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
Step( | |
function insertAll() { | |
var self = this; | |
collection.forEach(function(element) { | |
async(element, self.parallel()); | |
}); | |
}, | |
function finalize(err) { | |
if (err) { console.log(err);return;} | |
console.log('done with no problem'); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment