-
-
Notifications
You must be signed in to change notification settings - Fork 926
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
Provide a way to unsubscribe streams #2365
Comments
I'm not convinced this has to be a breaking change, BTW - you could make it purely additive, and I'd prefer a non-breaking solution better. |
Indeed, we can add some other way to end stream with dependent functions, either with another argument to |
@charlag Now that I take a closer look at this, it looks more like a design oversight.
So in reality, doing 1 and 2, not emitting to ended streams and deregistering them from their parent on I did notice another bug: the docs for "ended state" state "Ended streams still have state container semantics, i.e. you can still use them as getter-setters, even after they are ended", but the value isn't actually assigned unless the stream is opened |
@isiahmeadows thanks for looking at it! Should we discuss possible solutions or you would prefer to design it yourself? |
@charlag It's just as simple as doing these three things:
It's worth noting that this used to be the behavior, and it was accidentally broken in #2207. So although fixing this is non-breaking, the break is reverting a previous breaking change that resulted in 0 bug reports until now. 😉 There's a couple other issues, too. |
@isiahmeadows oh, neat, then it got broken when we updated Mithril 😅 I'm okay with adding a reference to the parent. While it's a cycling dependency, there should be no engines confused by that. |
@charlag I'm not going to require you to spot the other issues. A PR with the three bits listed above and a fix to correctly propagate stream ending should be sufficient. If you need any help while writing it, let me know. 🙂 |
Fixed by #2369 |
Description
The most common pattern for reactive programming is mapping/chaining streams. Unfortunately, current implementation of unsubscribing is not intuitive and creates small memory leaks.
Currently ending stream means "this stream is ended and it doesn't have any dependent streams anymore". What is surprising for me (and for other people) is that it doesn't mean "I let my parent stream know that I'm not interested anymore". In practice it leads to such code:
The person who wrote that (reasonably) expected, that the callback of "map" won't be executed, because it should be associated with the dependent stream. In reality callback is associated with the parent stream and the parent stream is not checking if dependent stream is closed or not before calling the callback:
Current workaround looks like this:
Note that
identity
function will still be called forever.Possible Implementation & Open Questions
Is this something you're interested in working on?
I can try to hack it together if we agree on approach.
Please note that this is a breaking change.
The text was updated successfully, but these errors were encountered: