将 combinelatest 触发其子节点的 doOnUnsubscribe [英] Will combinelatest trigger doOnUnsubscribe of its children
问题描述
不确定组合的可观察委托是否取消订阅其来源.
Not sure if the combined observable delegates doonunsubscribe to its sources.
如果没有,是否有一种简单的方法来触发其子项的取消订阅?
If not is there a simple way to trigger the unsubscribles of its children?
在代码中:
observable o = observable.combinelatest(o1, o2);
如果某事触发取消订阅 o 会触发取消订阅 o1 和 o2 吗?
If something triggers unsubscribe of o will it trigger the unsubscribe of o1 and o2?
推荐答案
不确定你的意思.
取消订阅被传播到 o1
和 o2
但如果你想执行自定义操作,你必须在所有相关方上使用 doOnUnsubscribe
:
Unsubscription is propagated to both o1
and o2
but if you want to perform custom actions, you have to use doOnUnsubscribe
on all relevant parties:
Observable<T> o = Observable.combineLatest(
o1.doOnUnsubscribe(() -> { }),
o2.doOnUnsubscribe(() -> { }))
.doOnUnsubscribe(() -> { });
o.take(1).subscribe();
但请注意,这些是全局链(而不是每个订阅者)的操作,对 o
的第二次订阅/取消订阅可能会再次调用它们.如果您需要按订阅者进行资源管理,请查看 using
运算符.
But note that these are chain-global (instead of per-subscriber) actions and a second subscription/unsubscription to o
may call them again. If you need per-subscriber resource management, look at the using
operator.
这篇关于将 combinelatest 触发其子节点的 doOnUnsubscribe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!