在RxSwift中手动处理DisposeBag

时间:2021-12-30 18:15:03

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?

因为我有disposeBag对象,除了我上面提到的那个之外,有没有一种方法可以取消请求?

2 个解决方案

#1


14  

You have to just change reference to your disposeBag object. Make it nil or assign new object to disposeBag.

您只需更改对disposeBag对象的引用即可。将它设为零或将新对象分配给disposeBag。

All request will be cancelled.

所有请求都将被取消。

#2


3  

Another option, besides deallocating a DisposeBag, is to use CompositeDisposable, which has an explicit dispose method.

除了释放DisposeBag之外,另一个选择是使用CompositeDisposable,它具有显式的dispose方法。

#1


14  

You have to just change reference to your disposeBag object. Make it nil or assign new object to disposeBag.

您只需更改对disposeBag对象的引用即可。将它设为零或将新对象分配给disposeBag。

All request will be cancelled.

所有请求都将被取消。

#2


3  

Another option, besides deallocating a DisposeBag, is to use CompositeDisposable, which has an explicit dispose method.

除了释放DisposeBag之外,另一个选择是使用CompositeDisposable,它具有显式的dispose方法。