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

cleanup: consider splitting "complete" vs "error" #78

Closed
bakkot opened this issue Oct 11, 2023 · 5 comments
Closed

cleanup: consider splitting "complete" vs "error" #78

bakkot opened this issue Oct 11, 2023 · 5 comments

Comments

@bakkot
Copy link
Contributor

bakkot commented Oct 11, 2023

Right now there is a proposed finally which is called regardless of how the observable is closed.

Web streams split this into two hooks: one called on normal exit, one called on error. (There is an old issue suggesting a finally, but there's no movement on it.)

It may be desirable to match web streams. Or it may not. I moderately prefer a single hook personally, although in some scenarios it's nice to know which kind of exit this was.

@benlesh
Copy link
Collaborator

benlesh commented Dec 19, 2023

@bakkot this is more akin to finally() on a promise. The use case is clean up of things you may have started during observation or via side-effects from within different methods. If I'm understanding this request, it's around a desire to fire a callback if the stream is aborted or unsubscribed by the consumer. In practice, finally (or finalize in RxJS) is only sometimes used to "know" when someone has aborted/unsubscribed from the stream — and even then, it's usually not a good pattern. The only valid use case I could think of to want to know when the consumer unsubscribed specifically would be for some sort of verbose logging.

@domfarolino
Copy link
Collaborator

If I'm understanding this request, it's around a desire to fire a callback if the stream is aborted or unsubscribed by the consumer.

This doesn't sound correct, right? The original concern sounds producer-focused, to provide a way to detect error() vs complete() from the producer. Not about separating out whether the consumer did anything.

In general though, I do agree with the Promise finally() analogy, and wonder what the efficacy of splitting the two would be.

@domfarolino
Copy link
Collaborator

I just want to check in on this thread after #49 has landed. @bakkot what do you think of the some of the comments above? Did they clear up the utility for finally(), to you?

@bakkot
Copy link
Contributor Author

bakkot commented Jan 30, 2024

It's less that I was unsure about the utility and more that I wanted to raise the possibility of aligning with the precedent in web streams, which are similar in some ways. If that alignment isn't worth it, that's fine.

@bakkot bakkot closed this as completed Jan 30, 2024
@domfarolino
Copy link
Collaborator

I see. It's tricky because it seems like there's precedent set by both streams (splitting the hooks, as you mentioned), and also Promises (with Promise.prototype.finally()). I hope the alignment with Promises won't be too confusing for people though.

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

No branches or pull requests

3 participants