clean-architecture-components-boilerplate
clean-architecture-components-boilerplate copied to clipboard
CompositeDisposable dispose vs clear in FlowableUseCase
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.
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)."
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 :)
tapi ga gitu bang