Skip to content

Commit 3d7ec04

Browse files
authored
Fix SubscriberAdapter calling onStart; leads to double calls sometimes. (#152)
1 parent f648934 commit 3d7ec04

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

Diff for: rxjava-reactive-streams/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description = "Adapter between RxJava and ReactiveStreams"
33
apply plugin: 'java'
44

55
dependencies {
6-
compile 'io.reactivex:rxjava:1.1.6'
6+
compile 'io.reactivex:rxjava:1.1.8'
77
compile 'org.reactivestreams:reactive-streams:1.0.0'
88
testCompile 'org.reactivestreams:reactive-streams-tck:1.0.0'
99
}

Diff for: rxjava-reactive-streams/src/main/java/rx/internal/reactivestreams/SubscriberAdapter.java

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public void onSubscribe(final Subscription rsSubscription) {
3737
if (started.compareAndSet(false, true)) {
3838
RxJavaSynchronizedProducer sp = new RxJavaSynchronizedProducer(rsSubscription);
3939
rxSubscriber.add(sp);
40-
rxSubscriber.onStart();
4140
rxSubscriber.setProducer(sp);
4241
} else {
4342
rsSubscription.cancel();

Diff for: rxjava-reactive-streams/src/test/java/rx/reactivestreams/TckSubscriberBlackboxTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public TckSubscriberBlackboxTest() {
3737

3838
@Override
3939
public Subscriber<Long> createSubscriber() {
40-
return new SubscriberAdapter<Long>(new rx.Subscriber<Long>() {
40+
rx.Subscriber<Long> rxSubscriber = new rx.Subscriber<Long>() {
4141

4242
@Override
4343
public void onStart() {
@@ -58,7 +58,9 @@ public void onError(Throwable e) {
5858
public void onNext(Long aLong) {
5959
request(1);
6060
}
61-
});
61+
};
62+
rxSubscriber.onStart(); // Observable.subscribe() calls this automatically
63+
return new SubscriberAdapter<Long>(rxSubscriber);
6264
}
6365

6466
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Copyright 2016 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package rx.reactivestreams.test;
17+
18+
import org.reactivestreams.Publisher;
19+
import org.testng.annotations.Test;
20+
21+
import rx.*;
22+
import rx.functions.Func1;
23+
24+
public class WrapUnwrap {
25+
26+
@Test
27+
public void wrapUnwrap() {
28+
29+
Observable<Integer> o = Observable.range(1, 350);
30+
31+
Observable<Publisher<Integer>> p = Observable.just(
32+
RxReactiveStreams.toPublisher(o)).asObservable();
33+
34+
for (int u : p.flatMap(new Func1<Publisher<Integer>, Observable<Integer>>() {
35+
@Override
36+
public Observable<Integer> call(Publisher<Integer> v) {
37+
return RxReactiveStreams.toObservable(v);
38+
}
39+
})
40+
.toBlocking()
41+
.toIterable()) {
42+
System.out.println(u);
43+
}
44+
45+
}
46+
}

0 commit comments

Comments
 (0)