19
19
import io .reactivex .disposables .Disposable ;
20
20
import io .reactivex .exceptions .Exceptions ;
21
21
import io .reactivex .functions .BiFunction ;
22
- import io .reactivex .internal .disposables .* ;
22
+ import io .reactivex .internal .disposables .DisposableHelper ;
23
23
import io .reactivex .observers .SerializedObserver ;
24
- import io .reactivex .plugins .RxJavaPlugins ;
25
24
26
25
public final class ObservableWithLatestFrom <T , U , R > extends AbstractObservableWithUpstream <T , R > {
27
26
final BiFunction <? super T , ? super U , ? extends R > combiner ;
@@ -38,6 +37,8 @@ public void subscribeActual(Observer<? super R> t) {
38
37
final SerializedObserver <R > serial = new SerializedObserver <R >(t );
39
38
final WithLatestFromObserver <T , U , R > wlf = new WithLatestFromObserver <T , U , R >(serial , combiner );
40
39
40
+ t .onSubscribe (wlf );
41
+
41
42
other .subscribe (new Observer <U >() {
42
43
@ Override
43
44
public void onSubscribe (Disposable s ) {
@@ -68,6 +69,7 @@ static final class WithLatestFromObserver<T, U, R> extends AtomicReference<U> im
68
69
private static final long serialVersionUID = -312246233408980075L ;
69
70
70
71
final Observer <? super R > actual ;
72
+
71
73
final BiFunction <? super T , ? super U , ? extends R > combiner ;
72
74
73
75
final AtomicReference <Disposable > s = new AtomicReference <Disposable >();
@@ -80,9 +82,7 @@ static final class WithLatestFromObserver<T, U, R> extends AtomicReference<U> im
80
82
}
81
83
@ Override
82
84
public void onSubscribe (Disposable s ) {
83
- if (DisposableHelper .setOnce (this .s , s )) {
84
- actual .onSubscribe (this );
85
- }
85
+ DisposableHelper .setOnce (this .s , s );
86
86
}
87
87
88
88
@ Override
@@ -116,43 +116,22 @@ public void onComplete() {
116
116
117
117
@ Override
118
118
public void dispose () {
119
- s . get (). dispose ();
119
+ DisposableHelper . dispose (s );
120
120
DisposableHelper .dispose (other );
121
121
}
122
122
123
- @ Override public boolean isDisposed () {
124
- return s .get ().isDisposed ();
123
+ @ Override
124
+ public boolean isDisposed () {
125
+ return DisposableHelper .isDisposed (s .get ());
125
126
}
126
127
127
128
public boolean setOther (Disposable o ) {
128
- for (;;) {
129
- Disposable current = other .get ();
130
- if (current == DisposableHelper .DISPOSED ) {
131
- o .dispose ();
132
- return false ;
133
- }
134
- if (current != null ) {
135
- RxJavaPlugins .onError (new IllegalStateException ("Other subscription already set!" ));
136
- o .dispose ();
137
- return false ;
138
- }
139
- if (other .compareAndSet (null , o )) {
140
- return true ;
141
- }
142
- }
129
+ return DisposableHelper .setOnce (other , o );
143
130
}
144
131
145
132
public void otherError (Throwable e ) {
146
- if (this .s .compareAndSet (null , DisposableHelper .DISPOSED )) {
147
- EmptyDisposable .error (e , actual );
148
- } else {
149
- if (this .s .get () != DisposableHelper .DISPOSED ) {
150
- dispose ();
151
- actual .onError (e );
152
- } else {
153
- RxJavaPlugins .onError (e );
154
- }
155
- }
133
+ DisposableHelper .dispose (s );
134
+ actual .onError (e );
156
135
}
157
136
}
158
137
}
0 commit comments