Subscriptions should have a dispose method to close all EventSink
Amir-P opened this issue · comments
I think Centrifuge.Subscription
should have a dispose method to be called when it's removed from Centrifuge.Client
to free up resources and close all EvenSink
's.
@Amir-P hello, thanks! Probably you can provide more information and example of what you mean? Do you mean closing various stream controllers Subscription object has internally on removing Subscription from Client's registry? Or sth else? Definitely, clear example would help me understand your idea much better.
Right now when we're removing a subscription from our client, subscription.unsubscribe
is called and then it is removed from _subscriptions
in ClientImpl
. But Subscription
object has various StreamController
instances which is left open after subscription is removed. Hence if there is a listener on one of the streams exposed by Subscription
class (e.g. publication), it will never get done event and get closed.
void main() async {
final controller = StreamController();
controller.stream.listen((_) {}, onDone: () => print('done'));
print(controller.hasListener); // prints out true
await controller.close(); // onDone gets called and 'done' will be printed
print(controller.hasListener); // prints out false
}
Let me know if I couldn't explain clearly again or got something wrong. @FZambia
Released in v0.9.2