On 8/21/13 12:03 AM, Tim Smart wrote:
> Sorry, one more time: https://gist.github.com/tim-smart/6290338
> 
> A simple state object makes a heap of difference in terms of code
> nesting. I'm not too sure if it has performance implications.

Hey Tim, why don't use waterfall from async to accomplish the very same
thing from your example? I've used it because it allows me to reuse a
lot of functions and if I need to remove one step is just one word in an
array and the rest works the same. Like:

```js
a = function(cb) {
  ...
  cb(null, data);
};

b = function(dataFromA, cb) {
  ...
  cb(null, data);
};

c = function(dataFromB, cb) {
  ...
  cb(null, result);
};

async.waterfall([a, b, c], function(err, results) {
  // results is the last data sent on the last callback,
  // this case from `c` and if some error happen then it
  // calls directly this function and handles the error
  // without going by any other of the functions.
  // In my case this is where `res.send`'s happens.
});
```

The error management is actually the reason why I use it even if there's
no data being sent between functions. If functions are written with a
modular approach (like they should), most of the first functions will be
reused (like permission stuff) and the last ones will be probably
customized case-by-case.

My ยข2.

-- 
Jose Luis Rivas
http://joseluisrivas.net/

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to