Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kaven276 opened this issue Nov 2, 2012 · 3 comments
Open

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

kaven276 opened this issue Nov 2, 2012 · 3 comments

Comments

@kaven276
Copy link

kaven276 commented Nov 2, 2012

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);
}
@kaven276
Copy link
Author

kaven276 commented Nov 2, 2012

so as async.waterflow, both step and async.waterflow is useless, it just save your a function name

@raffecat
Copy link

raffecat commented Nov 2, 2012

Yes, as an alternative to the async library, step is indeed superfluous if you happen to be using the async library. No trick necessary ;)

@dcporter
Copy link

"This module does the same thing as another module but with different words!"

This issue can probably be fruitfully closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants