clean-architecture-components-boilerplate icon indicating copy to clipboard operation
clean-architecture-components-boilerplate copied to clipboard

CompositeDisposable dispose vs clear in FlowableUseCase

Open joreilly opened this issue 8 years ago • 3 comments

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 avatar Dec 08 '17 11:12 joreilly

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)."

joreilly avatar Dec 08 '17 12:12 joreilly

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 :)

hitherejoe avatar Feb 21 '18 09:02 hitherejoe

tapi ga gitu bang

dwiyasko avatar Oct 30 '18 04:10 dwiyasko