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

Already on GitHub? Sign in to your account

Allow nested arrays in waterfall #109

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants

bcherry commented Feb 29, 2012

Hey there!

This is a pretty simple enhancement to waterfall, which flattens the tasks array prior to running the tasks. In practice, this means you can now pass sub-arrays of tasks in. This is handy because it allows you to create reusable tasks that can be included in waterfall workflows, where tasks can be waterfalls themselves.

For example:

function foo(done) {
  console.log('foo');
}

function bar(done) {
  console.log('bar');
}

function baz(done) {
  console.log('baz');
}

var foobar = [foo, bar];

async.waterfall([
  foobar,
  baz
]);

// logs foo, bar, baz

What do you think?

(this is inspired by Connect middleware's similar behavior)

rvagg commented Feb 29, 2012

It's always nicer to do your feature detection once only:

var _isArray = Array.isArray
  ? function (obj) { return Array.isArray(obj); }
  : function (obj) { return Object.toString.call(obj) === "[object Array]"; }

bcherry commented Feb 29, 2012

@rvagg Good call. How about:

var _isArray = Array.isArray || function(obj) { return Object.toString.call(obj) === "[object Array]"; };

rvagg commented Feb 29, 2012

touché

Owner

caolan commented Mar 28, 2014

If someone wants to rebase this onto master and write docs then please re-open and I'll merge

@caolan caolan closed this Mar 28, 2014

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