Created
January 11, 2012 21:53
-
-
Save joubertnel/1596981 to your computer and use it in GitHub Desktop.
verbose coordination of async operations on a sequence
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 readSource(after) { | |
var remainingWork; | |
var fileContents; | |
console.log('Reading source files...'); | |
remainingWork = settings.src.length; | |
fileContents = new Array(remainingWork); | |
settings.src.forEach(function(f, index) { | |
fs.readFile(f, function(err, data) { | |
fileContents[index] = {'file': f, | |
'data': data}; | |
remainingWork = remainingWork - 1; | |
if ((remainingWork === 0) && after) after(fileContents); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment