Skip to content

Commit

Permalink
Merge pull request #3055 from davidmoten/single-subscribe-fix
Browse files Browse the repository at this point in the history
toSingle() should use unsafeSubscribe
  • Loading branch information
benjchristensen committed Jul 14, 2015
2 parents f7d3b9c + a9f13b7 commit 9269692
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/rx/internal/operators/OnSubscribeSingle.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void onNext(T t) {
}
};
child.add(parent);
observable.subscribe(parent);
observable.unsafeSubscribe(parent);
}

public static <T> OnSubscribeSingle<T> create(Observable<T> observable) {
Expand Down
26 changes: 23 additions & 3 deletions src/test/java/rx/internal/operators/OnSubscribeSingleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
*/
package rx.internal.operators;

import static org.junit.Assert.assertFalse;

import java.util.Collections;
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicBoolean;

import org.junit.Test;

import rx.Observable;
import rx.Single;
import rx.functions.Action0;
import rx.observers.TestSubscriber;

import java.util.Collections;
import java.util.NoSuchElementException;

public class OnSubscribeSingleTest {

@Test
Expand Down Expand Up @@ -70,4 +75,19 @@ public void testRepeatObservableThrowsError() {

subscriber.assertError(IllegalArgumentException.class);
}

@Test
public void testShouldUseUnsafeSubscribeInternallyNotSubscribe() {
TestSubscriber<String> subscriber = TestSubscriber.create();
final AtomicBoolean unsubscribed = new AtomicBoolean(false);
Single<String> single = Observable.just("Hello World!").doOnUnsubscribe(new Action0() {

@Override
public void call() {
unsubscribed.set(true);
}}).toSingle();
single.unsafeSubscribe(subscriber);
subscriber.assertCompleted();
assertFalse(unsubscribed.get());
}
}

0 comments on commit 9269692

Please sign in to comment.