Created
October 15, 2012 10:21
-
-
Save gjtorikian/3891844 to your computer and use it in GitHub Desktop.
Using async module's queue to avoid EMFILE with fs.readFile
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 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