-
Notifications
You must be signed in to change notification settings - Fork 8
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
EventSubscription could be released with Dispose #46
Comments
Hi, @SebastianStehle! I agree with the idea, just not sure how to implement them yet. I'd like a solution that doesn't involve exposing anything different than we have today. This should probably be handled internally by the library objects (for example, saving a reference to the "unsubscribe" subject). What do you think? |
I noticed - by making the mistake in my application - that even such a simple case where you want to subscribe forever is also buggy:
This is how I implemented it in C#: The subscriptions are managed by a subscriber per event. If you have 10 .NET subscriber only one subscription is created to rust. it works similar to Reactive RefCount operator that converts a cold to a hot subscription. https://github.com/SebastianStehle/ydotnet/blob/improve-output/YDotNet/Document/Doc.cs#L73 The subscriber also catches exceptions, which is super important to avoid any unpredictable problems in rust: Furthermore the subscriber adds itself to a event manager that exists per doc, this keeps the subscription alive as long as the document lives: |
Hi, @SebastianStehle! About this:
You mean the If so, this scenario is already fixed in a different way as I mentioned in this comment. Your solution looks good to me as well, it's just a bit heavier because of the extra code to "intermediate" the callback process. |
If it would be a NullReferenceException it would be great, but it is TargetInvocationException or something similar that cannot be catched.
Yes, your solution was also my first approach, but then you have to store the event subscription somewhere, even if you never unsubscribe. I made this mistake in my application code and then I changed it. I actually built the subscriber for something else. The idea was to subscribe on the root types when they are created the first time and then use the event to mark on branches as deleted when they are removed from an array or map or so. Then I would have an open subscription anyway and could reuse that for the user subscription. But the array event does not expose the old values (yet?), so it does not work. |
Hi, @SebastianStehle! Now that #55 is merged and the |
I have seen that there is the open task to call dispose on the EventSubscription. We could just use the Dispose method to unsubscribe, e.g.
Advantages:
The text was updated successfully, but these errors were encountered: