Skip to content

Instantly share code, notes, and snippets.

@AvianFlu
Created August 8, 2011 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AvianFlu/1131154 to your computer and use it in GitHub Desktop.
Save AvianFlu/1131154 to your computer and use it in GitHub Desktop.
How to not nest your callbacks.
var fs = require('fs'),
total = '';
function readAndConcat(files) {
files.forEach(gotFile);
}
function gotFile(file) {
fs.readFile(file, useData);
}
function useData(err, data) {
if (err) { return; }
total += data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment