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
Add SerialSubscription #183
Comments
What do you think? If it makes sense, I may take up the task. |
Hey there :) Yah, we've had this request a couple of times. I think we've always just said "You can do it manually." E.g. CompositeSubscription could be done like so I'd be open to this contribution. If you take it up, could you please ensure you write tests for each class? Thanks! |
This commit add CompositeSubscription util class as described in issue ReactiveX#183 CompositeSubscription is a container for subscriptions making easy to cancel all added subscriptions at once. This Composite implementation is ported from RxJava's implementation of the same concept
…at once (#191) * Add CompositeSubscription class and docs This commit add CompositeSubscription util class as described in issue #183 CompositeSubscription is a container for subscriptions making easy to cancel all added subscriptions at once. This Composite implementation is ported from RxJava's implementation of the same concept * Add test for CompositeSubscription This test checks three properties of composite: - it should cancel every added subscription on clear and dispose - if removed from composite, subscription won't cancel on clear and dispose - it should throw an error instead of adding subscriprtion if it was disposed * Add CompositeSubscription file to export * Format the PR with the `dartfmt` tool * Replace /** */ style docs with /// to adhere dart guidelines * Specify explicit <dynamic> type annotations * Fix type annotations in tests * Register CompositeSubscription in test runner CompositeSubscription tests weren't running on the CI because they weren't included in the test suite * Make composite cancel subscription on remove This is more compliant to RxJava CompositeSubscription behaviour * Remove Java-like fluent interface In Dart, method cascades can make auto-fluent interfaces for free, So methods like `add` can now return the subscription added, not the composite This makes API more versatile and adaptable for more usecases
CompositeSubscription now added. Changing the title. Thanks @Mishkun :) |
how about |
CompositeSubscription
Basically a bag for multiple subscription (with
add
andremove
methods) that can be unsubscribed at once: http://reactivex.io/RxJava/javadoc/io/reactivex/disposables/CompositeDisposable.htmlIt's very useful when you listen to multiple streams and want to dispose them all at once (e.g. when a widget in Flutter is disposed).
Danger of this one is that developers add thousands of subscriptions (e.g. for a repeatable task). In RxJava at least the "bag" is never emptied, even if the streams already emptied.
SerialSubscription
A container that keeps track of a single subscription, and you can replace the subscription with another one (
set
method), which cancels the previous subscription: http://reactivex.io/RxJava/javadoc/io/reactivex/disposables/SerialDisposable.htmlBasically a shorthand for:
I love this one. It ensures that subscriptions never get lost when you replace them. And you can also add them to
SerialSubscription
s.Add
subscription
argument todoOnListen
operatorUse case: Easily add/set a subscription without breaking the flow:
The text was updated successfully, but these errors were encountered: