-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
breaking the waterfall chain without throwing an error #11
Comments
Hi, you probably solved your issue by now, btw this is my approach:
When a function calls a callback with |
I have a similar issue & i am adding a callback wrapper(which i could avoid) just to check whether its an error or not for every waterfall that i use. Its not that clean when there are more than one waterfalls.
i wont have to wrap the callback & it could be chained to rest of the program. |
@caolan is there anything you dont like about @jnordberg pull request? And if so is there something I can do to get this pull request accepted? |
@tax : actually I found that we can skip to the final function by passing 'error' = true like this: async.waterfall([function (callback) { |
@tot2ivn thanks for the tip! |
If you set the error the result will be empty though.
|
Personally I find myself needing functionality like this and think it should be added to the core library. Here is my helper workaround if anyone is interested...
If you need to break to the last function within a task just call the callback like this: The helper just detects the |
I was told I need to refactor my code that is using async waterfall. I used it primarily because I had several chained functions that were going too deep, and I wanted to reuse a function, etc. There is a condition at one point down the chain that is not strictly an error condition, but that I don't want to pass down the rest of the waterfall chain, because it's useless - say for example I did a query and there are no results, and that's not an error, I don't want to propagate all the way down with no results. If I were doing this without async, I guess I would have a "final" callback and which could be called to break out of the chain without explicitly throwing an error. This functionality doesn't seem to be present in waterfall. Is there a way to do this cleanly? The only way I can see to do it is to throw a special error and then handle that on the final callback so as to return a non error.
The text was updated successfully, but these errors were encountered: