Skip to content

Instantly share code, notes, and snippets.

@r01010010
Created November 23, 2014 23:02
Show Gist options
  • Save r01010010/c4ef8ce2f91de31d1200 to your computer and use it in GitHub Desktop.
Save r01010010/c4ef8ce2f91de31d1200 to your computer and use it in GitHub Desktop.
var data = fs.readFileSync('/etc/passwd');
/* This code would start 1000 simultaneous asynchronous file reads, and run the do_next_part()
function immediately. This has several problems: first, we’d like to wait until
all the file reads are done until going further.*/
for(var i = 1; i <= 1000; i++) {
fs.readFile('./'+i+'.txt', function() {
// do something with the file
});
}
do_next_part();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment