Skip to content

Instantly share code, notes, and snippets.

@alvesjnr
Created June 30, 2011 19:03
Show Gist options
  • Select an option

  • Save alvesjnr/1056929 to your computer and use it in GitHub Desktop.

Select an option

Save alvesjnr/1056929 to your computer and use it in GitHub Desktop.
Callback Counters
var counter = 2;
fs.readFile(__filename, onRead);
fs.readFile("/etc/passwd", onRead);
function onRead(err, content) {
if (err) throw err;
// Do something with content
counter--;
if (counter === 0) done();
}
function done() {
// Now both are done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment