4
在代碼中,我需要釋放一些取消訂閱上的資源(它在哪裏記錄「發佈」)。RxJava:不會調用訂閱的取消訂閱()方法
Observable first = Observable.create(new Observable.OnSubscribe<Object>() {
@Override
public void call(Subscriber<? super Object> subscriber) {
subscriber.add(Subscriptions.create(() -> {
log(「release」);
}));
}
}).doOnUnsubscribe(() -> log(「first」));
Observable second = Observable.create(…).doOnUnsubscribe(() -> log(「second」));
Observable result = first.mergeWith(second).doOnUnsubscribe(() -> log(「result」));
Subscription subscription = result.subscribe(…);
//…
subscription.unsubscribe();
但它只記錄「結果」。看起來退訂不會傳播給合併的孩子觀察對象。那麼如何處理第一個observable的Observable.OnSubscribe內部的取消訂閱?