Created
July 1, 2011 00:11
-
-
Save chbrown/1057596 to your computer and use it in GitHub Desktop.
Wait function for reading files async.
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 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