Add a 'waterfall' method #1

Closed
mcavage opened this Issue Jun 8, 2012 · 3 comments

Projects

None yet

3 participants

mcavage commented Jun 8, 2012

Sometimes it's really much more useful if I can pass a cookie through the chain. the async module calls this waterfall (I really don't care about the name). Here's a snippet of what I'd like this to act like. Discuss :)

1  vasync.waterfall({
2          funcs: [
3                  function one(input, cb) {
4                          // Will be { count: 1 }                                                                                                                                                   
5                          cb(null, { count: input.count++ });
6                  },
7                  function two(input, cb) {
8                          // Will be {count: 2 }                                                                                                                                                    
9                          cb(null, { count: input.count * 2 });
10                 }
11         ],
12         arg: { count: 1 }
13 }, function (err, res) {
14         assert.ifError(err);
15         // Since this is all "pass-through", ideally add                                                                                                                                          
16         // a res.output or something (i.e., either there was an error,                                                                                                                            
17         // or this went all the way through, so really, it would be                                                                                                                               
18         // nice to see res.output.                                                                                                                                                                
19         console.log(res.output); // => { count: 4 }                                                                                                                                               
20 });
mcavage commented Jun 8, 2012

Oh drat - sorry I kept the linenums in there. Stupid terminal copy/paste.

@davepacheco davepacheco self-assigned this Mar 13, 2014
swaj commented Apr 2, 2014

+1 for us. We're using this function in the async library pretty extensively and I'd love to switch to vasync instead.

Owner

Merged under 410780b.

@davepacheco davepacheco closed this May 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment