-
Notifications
You must be signed in to change notification settings - Fork 25
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
Gracefully exit a pipeline or waterfall [discussion] #23
Comments
Can you give a little more detail on your use case? It doesn't sound like what pipeline() and waterfall() were created for, but maybe there's another (similar) abstraction that would be useful here. |
Here's an example:
And so on. I don't want to call every 3rd party API every time because it's both unnecessary and could potentially get $$ expensive. |
I considered node-workflow but it seems a little more than what I need in this particular instance. |
That workflow makes sense (of course). Usually when I want to do this, I have steps 3-4 check whether the condition from step 2 is already met. In my experience, this is usually cleanest when the whole operation's state is encapsulated in an object, then step 2 updates that state, and subsequent steps check that state and potentially call their callback immediately. I like being explicit about what's being skipped and why. Here's an example, though it's less clean and uses local variables instead of an object: In that example, the optional "outstream" parameter determines whether several steps toward the end of the pipeline need to happen at all. I'm not saying this pattern is great, but on the plus side, the full-length path is pretty clear, and the code for bailing out early in some cases is explicit and clear too. So there are a few options:
|
I keep running into a situation where I don't need to continue a pipeline or a waterfall because a certain condition has been met.
One way to handle this is to return an error, which exits. The "problem" is that this is recorded as a failure, which really wasn't the case. Alternatively, I could pass a boolean var
done
along the pipeline and just skip the function if done.It seems like there should be a better option to exit gracefully. Maybe a special exception class that causes the exit to not be reported as a failure?
The text was updated successfully, but these errors were encountered: