Skip to content

Instantly share code, notes, and snippets.

@pgte
Created February 27, 2011 11:36
Show Gist options
  • Save pgte/846119 to your computer and use it in GitHub Desktop.
Save pgte/846119 to your computer and use it in GitHub Desktop.
async_function.js
function async(i, callback) {
timeout = Math.round(Math.random() * 3000);
setTimeout(function() {
console.log(i + ' is done');
callback();
}, timeout);
}
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