我正在搜索doOn ...回调以查找每个观察者终止时调用的ConnectableObservable
val gatewayItems = viewModel.getGatewayItems(gateways!!)
.observeOn(Schedulers.io())
.take(1)
.publish()
.autoConnect(2)
gatewayItems.subscribe { sharedGateways -> sharedGatewaysAdapter.submitList(sharedGateways) }
gatewayItems.subscribe { sharedGateways -> privateGatewaysAdapter.submitList(privateGateways) }
当我的两个观察者都发出终端事件信号时,我希望获得对多播热点可观察性的回调
我尝试将doOnTerminate和doOnComplete运算符放在多播的父级上可观察到,但似乎这些回调被调用了2次(每个观察者一个)
答案 0 :(得分:0)
val gatewayItems = viewModel.getGatewayItems(gateways!!)
.observeOn(Schedulers.io())
.take(1)
.doOnComplete { ... }
.doOnTerminate { ... }
.publish()
.autoConnect(2)
.doOnComplete
和.doOnTerminate
都为我工作。
编辑:您可能会以错误的顺序附加do...
运算符。例如,这两个doOnComplete
都不起作用:
val gatewayItems = viewModel.getGatewayItems(gateways!!)
.observeOn(Schedulers.io())
.doOnComplete { ... }
.take(1)
.publish()
.autoConnect(2)
.doOnComplete { ... }