Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toSingle() should use unsafeSubscribe #3055

Merged
merged 1 commit into from
Jul 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}