I have an observable that is performing a download. However I want to cancel that observable when I click on a button.
How is that possible?
Thank you.
In my case I had a Publish subject that was emitting items in a certain condition. In some condition I wanted to cancel it, So I added a sealed class that holds the state:
sealed class DelayedItem {
object Ignore : DelayedItem()
data class Handle(val text: String) : DelayedItem()
}
And my subscriber was bounced like that:
myPublishSubject
.subscribeOn(Schedulers.io())
.debounce(500, TimeUnit.MILLISECONDS)
.subscribe {
if (it is DelayedItem.Handle)
handleItem(it)
}
Hope it helps!