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

CompositeDisposable dispose vs clear in FlowableUseCase #14

Open
joreilly opened this issue Dec 8, 2017 · 3 comments
Open

CompositeDisposable dispose vs clear in FlowableUseCase #14

joreilly opened this issue Dec 8, 2017 · 3 comments

Comments

@joreilly
Copy link

joreilly commented Dec 8, 2017

Have adapted some of this code for my own project and one issue I ran in to was around use of CompositeDisposable.dispose() in FlowableUseCase for case where I need to update the subscription. In my case at least switching to clear resolved the issue. It looks like calling dispose has effect of not allowing subsequent use of disposables.

@joreilly
Copy link
Author

joreilly commented Dec 8, 2017

https://medium.com/@CodyEngel/managing-disposables-in-rxjava-2-for-android-388722ae1e8a takes a different approach...it creates a new CompositeDisposable if isDisposed() is true. From that article:

" The reason for this is when you call dispose() that CompositeDisposable may as well no longer exist (as in, don’t add anything else to it because you’ll just be disappointed and frustrated when nothing works)."

@hitherejoe
Copy link
Collaborator

Sorry for the late reply on this one! Yea dispose() means that you will no longer be able to add disposables to that composite disposable, clear() means you can - it just clears the disposables that are currently held within the instance.

The article has a nice idea but I would avoid having a Singleton to handle that, a lot of the responses there are thinking the same thing! You could have a disposable helper class which you could use to validate the composite disposable instance if you wanted to however :)

@dwiyasko
Copy link

tapi ga gitu bang

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

No branches or pull requests

3 participants