-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Synchronous Unsubscribe #266
Comments
Oh... additional question: Would it be possible to add this to our API without changing much about our existing operator implementations? My gut tells me "yes", but I haven't investigated this throughly. also (+@trxcllnt) |
Just my 2 cents, I never felt the need to access the subscription inside subscribe, so I am not sure why we want to complicate the API with that. |
Your 2 cents is greatly appreciated, @headinthebox. Can you elaborate as to why you don't feel the need to access the subscription inside subscribe? My gut tells me that without the need for RxJava-style backpressure, it's probably a special Rx flavor of code-smell to access subscription inside of the subscribe function. But I don't know what I don't know (hence this thread). |
It is a huge code smell, since you are probably doing something (stateful) that you should do with an operator. If you really want to unsubscribe from within say the |
Unknown. It's been brought up by @jhusain and @trxcllnt many times, and I wanted to have an issue to discuss and track it. In a recent hallway conversation with @jhusain, I was told @zenparsing refuted the need for this API really well. I'd like to capture some of that. |
@headinthebox If Observer stored the Subscription injected into |
In my opinion, sending data to the observer before Let's call sending data to the observer before Moreover, Rx has a long history and the lack of "synchronous unsubscription" does not seem to have resulted in any gaping functional holes (as far as I can tell). Our perspectives are a little different. I'm thinking in terms of the JS standard library, and for the standard library, there's a seeming paradox at play: the simpler the abstraction is, the more broadly useful it is. Consequently, I'm in favor of keeping Observables as simple as possible (more simple than Rx, even), not making them more complex. Moreover, I don't think we should have a RxJava-style |
I've tried and failed to come up with a good example of why synchronous unsubscription is useful. At this point I'm inclined to agree with Kevin unless someone can come up with really good reason for synchronous unsubscription. JH
|
We seem to talk a lot about sources that synchronously send events, but in practice, in my experience, you only do that for "demos", just to have some quick and dirty sample input. If a source is really synchronous you are better off using an iterable instead, and it is kind of stupid to make it "push". But that is another discussion. Say you cannot use Most importantly however, not that if you pass in the handlers separately, there is no way you can get at the |
I'm going to close this discussion for now. It seems like we can't come up with a valid use case to alter the current design/architecture. At the very least, this discussion has died off, and I can close this issue. ... this does not, of course, mean that we won't consider making the proposed changes should we identify a valid need or reason to do so. |
cc @zenparsing ^^^ |
No, because calling |
I'm mostly thinking of custom EventTarget implementations. Is there anything specified that prohibits someone from implementing an |
Someone could write their own EventTarget-ish thing that does that, but they shouldn't. : ) I just looked up Node's EventEmiiter and it does in fact fire an event when https://github.com/nodejs/node/blob/master/lib/events.js#L204 However, it will never actually execute the provided callback before returning. |
The Proposal
So currently we don't support synchronous unsubscription because of our API. What has been/is being proposed is a RxJava-style solution (not with backpressure, just with the start handler):
It looks like this:
Observer interface changes to:
All this means is that the execution of a synchronous function will get access to an
unsubscribe
method as soon as subscription occurs.Explanation of "Synchronous Unsubscribe"
Consider the following with the current version of RxJS Next:
If you subscribe to a synchronous Observable, the returned subscription object is pointless, because it's always going to be unsubscribed by the time you hit the next line in your current block of code.
Now if you were able to get access to the Subscriber (which has all Subscription logic on it) in a start method at subscription time:
Unanswered Questions
take
for example) more performant?Other Things
If/whenever an RxFlowable library (@benjchristensen) is developed for JS, it will be essentially a mirror of this library geared for server/node use with the addition of backpressure. It will most likely have a
start()
handler on it, because the start handler is where you initialize backpressure by requesting the initial values. Adding this to our API may help people jump between the two types.@zenparsing has demonstrated how this API can make operators potentially very ugly to implement. He has also discussed this with @jhusain at length. It's doubtful that this API will make the es7 observable spec, which is a corner goal for this library.
/cc @headinthebox @mattpodwysocki
The text was updated successfully, but these errors were encountered: