Will combinelatest trigger doOnUnsubscribe of its children

本秂侑毒 提交于 2020-01-17 05:10:07

问题


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?

In code:

observable o = observable.combinelatest(o1, o2);

If something triggers unsubscribe of o will it trigger the unsubscribe of o1 and o2?


回答1:


Not sure what you mean.

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();

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.



来源:https://stackoverflow.com/questions/31122768/will-combinelatest-trigger-doonunsubscribe-of-its-children

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!