Add support for breaking a waterfall chain #85

Closed
wants to merge 2 commits into
from

Projects

None yet

4 participants

@jnordberg
Contributor

This patch allows for more fine-grained control of a waterfall chain. Calling callback.final at any point in the waterfall will jump to the completion callback skipping any steps left in the chain.

Refs #11

@anguyen8

Actually I found that we can skip to the final function by passing 'error' = true like this:

async.waterfall([function (callback) {
callback(null); // <--- go to next fn
},
function (callback) {
callback(true); // <--- skip to the last fn
},
function (callback) {
callback(null); // <--- this fn will not be called
}
], callback);

So your patch is probably not necessary. :)

@jamiesteven

jnordberg, this is useful functionality. I have a waterfall function that checks different datasources in order trying to find an object. If a match is found, than I'd like the waterfall to skip the remaining functions and go straight to the final callback for rendering.

tot2ivn, while your approach works, the results aren't passed through, and this doesn't work if you've built custom error handling.

@caolan
Owner
caolan commented Feb 4, 2013

I think in this circumstance you could use a closure and async.whilst or async.until, or just use a named function for the final callback and call that instead of the task callback passed into the successful task function.

@caolan caolan closed this Feb 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment