Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gjtorikian
Created October 15, 2012 10:21
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 gjtorikian/3891844 to your computer and use it in GitHub Desktop.
Save gjtorikian/3891844 to your computer and use it in GitHub Desktop.
Using async module's queue to avoid EMFILE with fs.readFile
var fs = require("fs"),
async = require("async");
var q = async.queue(function (task, callback) {
if (task.type == "file")
fs.readFile(task.path, "utf8", callback);
}, 250);
dirFiles.forEach(function(path) {
q.push({type: "file", path: path}, function (err, fileString) {
if (err) {
console.error(err);
process.exit(1);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment