|
34 | 34 | import rx.Observer;
|
35 | 35 | import rx.Subscription;
|
36 | 36 | import rx.subscriptions.Subscriptions;
|
| 37 | +import rx.util.AtomicObservableSubscription; |
| 38 | +import rx.util.SynchronizedObserver; |
37 | 39 | import rx.util.functions.Func1;
|
38 | 40 | import rx.util.functions.Func2;
|
39 | 41 | import rx.util.functions.Func3;
|
@@ -124,7 +126,7 @@ public void onNext(T args) {
|
124 | 126 | */
|
125 | 127 | private static class Aggregator<R> implements Func1<Observer<? super R>, Subscription> {
|
126 | 128 |
|
127 |
| - private Observer<? super R> observer; |
| 129 | + private volatile Observer<? super R> observer; |
128 | 130 |
|
129 | 131 | private final FuncN<? extends R> combineLatestFunction;
|
130 | 132 | private final AtomicBoolean running = new AtomicBoolean(true);
|
@@ -228,19 +230,21 @@ public Subscription call(Observer<? super R> observer) {
|
228 | 230 | if (this.observer != null) {
|
229 | 231 | throw new IllegalStateException("Only one Observer can subscribe to this Observable.");
|
230 | 232 | }
|
231 |
| - this.observer = observer; |
| 233 | + |
| 234 | + AtomicObservableSubscription subscription = new AtomicObservableSubscription(new Subscription() { |
| 235 | + @Override |
| 236 | + public void unsubscribe() { |
| 237 | + stop(); |
| 238 | + } |
| 239 | + }); |
| 240 | + this.observer = new SynchronizedObserver<R>(observer, subscription); |
232 | 241 |
|
233 | 242 | /* start the observers */
|
234 | 243 | for (CombineObserver<R, ?> rw : observers) {
|
235 | 244 | rw.startWatching();
|
236 | 245 | }
|
237 | 246 |
|
238 |
| - return new Subscription() { |
239 |
| - @Override |
240 |
| - public void unsubscribe() { |
241 |
| - stop(); |
242 |
| - } |
243 |
| - }; |
| 247 | + return subscription; |
244 | 248 | }
|
245 | 249 |
|
246 | 250 | private void stop() {
|
|
0 commit comments