Skip to content

Instantly share code, notes, and snippets.

@clarkf
Created January 14, 2011 07:02
Show Gist options
  • Save clarkf/779298 to your computer and use it in GitHub Desktop.
Save clarkf/779298 to your computer and use it in GitHub Desktop.
var files = ['file1','file2','file3' /*...*/];
var counter = 0;
var length = 0;
var afterLoad = function () { /* all our files are loaded in here :) */ }
for (var i = 0; i < files.length; i++) {
//Increment length counter so we know that a request has been sent...
length++;
require('fs').readFile(files[i], function (data) {
//Increment counter variable so we know where we are
counter++;
if ( counter >= length ) {
afterLoad();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment