Skip to content

step is just no value, it's just a trick #44

Description

@kaven276

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);
}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions