I want to cancel a request and one of the ways is to manually remove the disposable bag.
.addDisposableTo(disposeBag)
As I have the disposeBag object, is there a good way to cancel the request other than that I mentioned above?
Thread safe bag that disposes added disposables on deinit . This returns ARC (RAII) like resource management to RxSwift . In case contained disposables need to be disposed, just put a different dispose bag or create a new one in its place. In case explicit disposal is necessary, there is also CompositeDisposable .
RxSwift: DisposeBag Used to avoid memory leaks as the subscription will not be disposed of correctly without. DisposeBag holds disposables. DisposeBag allows us not to have to dispose of each subscription individually.
You have to just change reference to your disposeBag object. Make it nil or assign new object to disposeBag.
All request will be cancelled.
Another option, besides deallocating a DisposeBag
, is to use CompositeDisposable
, which has an explicit dispose
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With