Created
July 21, 2014 23:38
-
-
Save kevzettler/d124ca0ade48d8353555 to your computer and use it in GitHub Desktop.
nodejs file reads
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
var q = async.queue(function (file, cb) { | |
console.log("from the queue::", file.path); | |
var stream = fs.createReadStream(file.path) | |
// ... | |
stream.on('end', function() { | |
// finish up, then | |
cb(); | |
}); | |
}, 2); | |
var globStream = gs.create(getGlobPaths()); | |
globStream.on('data', function(file) { | |
console.log("globStream::", file.path); | |
q.push(file); | |
}); | |
globStream.on('end', function() { | |
// We don't want to add the `drain` handler until *after* the globstream | |
// finishes. Otherwise, we could end up in a situation where the globber | |
// is still running but all pending file read operations have finished. | |
q.drain = function() { | |
// All done with everything. | |
}; | |
// ...and if the queue is empty when the globber finishes, make sure the done | |
// callback gets called. | |
if (q.idle()) q.drain(); | |
}); | |
Author
kevzettler
commented
Jul 21, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment