Skip to content
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 subscriptions directly to a CompositeSubscription #63

Merged
merged 1 commit into from
Jun 13, 2016
Merged

Add subscriptions directly to a CompositeSubscription #63

merged 1 commit into from
Jun 13, 2016

Conversation

KenVanHoeylandt
Copy link
Contributor

@KenVanHoeylandt KenVanHoeylandt commented Apr 26, 2016

This feature is inspired by RxSwift DisposeBag.

The idea is that you can add your Subscription directly (inline) to a CompositeSubscription rather than having it assigned to a separate val first and then manually adding it a CompositeSubscription after assignment.

Usage:

Observable.just("test")
        .delay(100, TimeUnit.MILLISECONDS)
        .subscribe()
        .addTo(compositeSubscription)

I chose the name addTo() so that other containers could be targeted in the future.
addTo() returns the original Subscription so that it could be called consecutively.

A practical usage would be the Android Fragment instances:
They have several important life cycle events such as "UI destroyed" and "Fragment destroyed". Subscription instances can be tied to these life cycle events through CompositeSubscription instances that are unsubscribed when the life cycle event happens.

I've created an example and added tests for this feature.

@MarioAriasC MarioAriasC merged commit 215a9f5 into ReactiveX:0.x Jun 13, 2016
@KenVanHoeylandt KenVanHoeylandt deleted the feature/subscription_addto branch June 13, 2016 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants