Skip to content

Instantly share code, notes, and snippets.

@scottgonzalez
Created December 20, 2011 15:56
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 scottgonzalez/1502051 to your computer and use it in GitHub Desktop.
Save scottgonzalez/1502051 to your computer and use it in GitHub Desktop.
var getFiles = Step.fn(
function readDir(dir) {
this.keep(dir);
fs.readdir(dir, this.parallel());
},
function readFiles(err, dir, results) {
if (err) throw err;
// Create a new group
var group = this.group();
results.forEach(function (filename) {
if (/\.js$/.test(filename)) {
fs.readFile(dir + "/" + filename, 'utf8', group());
}
});
}
);
getFiles(__dirname, function(err , files) {
if (err) throw err;
console.dir(files);
});
@creationix
Copy link

Actually, this isn't a bad idea. Also we can maybe merge this and this.parallel() since they do the same thing in the single case. People are constantly confused by the difference between this.parallel() and this.group(). Having one less API point may help the confusion.

@scottgonzalez
Copy link
Author

Merging this and this.parallel() would be fantastic. The fact that you'd have to use this.parallel() when using this.keep() was a concern of mine, since it'd be a potential pitfall for users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment