-
Notifications
You must be signed in to change notification settings - Fork 188
Open
Description
the code example in step's readme
Step(
function readDir() {
fs.readdir(__dirname, *this*); <--------
},
function readFiles(err, results) {
if (err) throw err;
// Create a new group
* var group = this.group() *; <--------
results.forEach(function (filename) {
if (/\.js$/.test(filename)) {
fs.readFile(__dirname + "/" + filename, 'utf8', *group()*); <--------
}
});
},
function showAll(err , files) {
if (err) throw err;
console.dir(files);
}
);
can just use this more clear code instead, replace all (this, this.group, this.async) away, step jsut play a trick, it sell you something you just have own already.
var fs = require('fs');
fs.readdir(__dirname, readFiles);
function readFiles(err, results){
if (err) throw err;
// Create a new group
async.map(results, function(filename, cb){ <-------- use async.map to finally get all async result
if (/\.js$/.test(filename)) {
fs.readFile(__dirname + "/" + filename, 'utf8', cb);
}
}, showAll);
}
function showAll(err, files){
if (err) throw err;
console.dir(files);
}
laheadle
Metadata
Metadata
Assignees
Labels
No labels