![](/img/trans.png)
[英]RxJava, wait for multiple Observables to provide desired result in the same time
[英]RxJava: Calling .subscribe() with same Observer for multiple Observables
同一個 Observer 在多個 Observable 上調用.subscribe()
的行為是什么?
它們會被隱式合並嗎? 或者是最后一次獲勝?
例如:
event1.subscribe(myObserver);
event2.subscribe(myObserver);
根據javadoc ,只要不取消每個 Observable 返回的Subscription
,觀察者就會訂閱所有 observable 。
我希望如果您多次訂閱同一個觀察者到一個 observable,您將多次收到通知 - 否則之前進行的訂閱會“神奇地”消失,這可能會導致麻煩。
// data members
Observable x, y;
void foo(Subscriber a) {
// is subscriber a already registered with x?
// Nevermind, I'm gonna make sure it is!
Subscription s=x.subscribe(a);
// provoke a change to be caught by 'a'
// do some work based on whatever Subscriber 'a' captured.
s.unsubscribe();
}
void bar() {
Subscriber m;
Subscription mx=x.subscribe(m);
Subscription my=y.subscribe(m);
// do something and then...
foo(mx); // one would expect the mx subscription is still valid here!!!
// do some more work
my.unsubscribe();
mx.unsubscribe();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.