-
Notifications
You must be signed in to change notification settings - Fork 12
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
Could the concepts of cancellation, closure, and unsubscription be merged? #23
Comments
It's all the concept of being "done" with something. The only big difference is between disinterest (I am no longer interested in X) and "destroy" (X needs to stop now) semantics. As long as we all agree on the former - whether we call it cancel, close, dispose, unsubscribe, complete or anything else that says "we are no longer interested in this thing" - it doesn't actually matter that much. I also don't think that's why this proposal isn't moving forward right now. |
The reason I filed this issue is because these two concepts, signaling disinterest and requesting termination, are often hand-in-hand. I was suggesting that this proposal focus on being "done" in general, rather than the reason why we're "done", because in my experience, those two reasons end up crossing paths more often than not in the face of composition, especially from "disinterest" to "destroy", due to resource leak prevention. For example:
It's not so much an academic thing as much as a pragmatic "I'd like to have only one way of doing things, one that integrates with things better" thing. It's worth noting that languages with explicit destructors, like C++ destructors, Swift's
I'm aware, and I wasn't trying to imply such. Sorry if this wasn't clear. |
This is really a shot in the dark, and I expect some initial resistance, but hear me out on this one.
I was thinking you could merge cancelling a request with closing a socket. I know these are two separate concepts, but they are heavily intertwined in practice.
This also extends to observables: you could subscribe with a close token instead of just subscribing and receiving an object with an
unsubscribe()
method and aclose
property - the close token would already have this info for you.Also, informally, I've seen these used quite interchangeably, with a heavy bias towards "close":
You probably notice I went from "cancel token" to "close token", talking about "closure" instead of "cancellation", and that's on purpose: I'm thinking you could merge cancellation and stream closure to a more abstract "close" operation. You could keep the existing cancel token API or something similar, but I feel there's a lot to be gained by having only one concept instead of 3.
The text was updated successfully, but these errors were encountered: