On Apr 17, 2013, at 2:42 AM, chakrit <[email protected]> wrote:
> One big glaring caveat with pipeworks though:
>
> Callback (the next() function in this case) should always accepts error as
> first argument.
>
> Otherwise you will break a lot of established pattern and convention with
> callback function usage.
>
> For example, how do you:
> Handle error when one of the pipe throws or wants to callback with new Error ?
> Use with other library that expect standard callback like `redis.get` ?
> From what I can see from your README I cannot pass `next()` to this function
> directly
> without wrapping it in a `function(e, result) { next(result); }` first to
> swap the arguments right?
> And what if there is an Error?
Hey, these are good questions. The call to next is usually meant to be called
directly from another pipe or a function that understands the same signature.
Not doing so will often mean you forfeit your context.
However, Pipeworks does support this! You can supply any number of arguments
into the flow.
Using your Redis example:
var pipeworks = require('pipeworks');
var redis = require('redis');
var client = redis.createClient();
var key = 'hello';
var value = 'how do you do?';
pipeworks()
.fit(function(err, res, next) {
client.set(key, value, next);
})
.fit(function(err, res, next) {
client.get(key, next);
})
.fit(function(err, res, next) {
if (err) {
console.log('ohnoes:', err);
next(err, res);
return;
}
console.log(res);
next(err, res);
})
.fit(function(err, res, next) {
client.quit();
next(err, res);
})
.flow(null, null);
Output: how do you do?
If there's an error, just pass it along. There's no out-of-the-box wrapper to
catch a throw in Pipeworks (nor should there be, in my opinion).
Cheers,
--
Kevin Swiber
@kevinswiber
https://github.com/kevinswiber
--
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.