Skip to content

Instantly share code, notes, and snippets.

@chbrown
Created July 1, 2011 00:11
Show Gist options
  • Save chbrown/1057596 to your computer and use it in GitHub Desktop.
Save chbrown/1057596 to your computer and use it in GitHub Desktop.
Wait function for reading files async.
function wait(count, callback) {
return function() {
if (--count === 0) {
callback();
}
}
}
var list_of_files = ['a', 'b', 'c'];
var report = wait(list_of_files.length, function() {
console.log("done with them all");
});
list_of_files.eachAsync(function (file_data) {
console.log('this file\'s data is', file_data);
report();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment