Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for breaking a waterfall chain #85

Closed
wants to merge 2 commits into from

Conversation

jnordberg
Copy link
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
Copy link

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. :)

@tacomilkshake
Copy link

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
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants