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

Cast back Observer to Subscriber if passed to subscribe(Observer) #2630

Merged
merged 1 commit into from
Feb 6, 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
3 changes: 3 additions & 0 deletions src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7289,6 +7289,9 @@ public final void onNext(T args) {
* @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX operators documentation: Subscribe</a>
*/
public final Subscription subscribe(final Observer<? super T> observer) {
if (observer instanceof Subscriber) {
return subscribe((Subscriber<? super T>)observer);
}
return subscribe(new Subscriber<T>() {

@Override
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/rx/ObservableTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1129,4 +1129,13 @@ public void testEmptyIsEmpty() {
verify(w, never()).onNext(any(Integer.class));
verify(w, never()).onError(any(Throwable.class));
}

@Test // cf. https://github.com/ReactiveX/RxJava/issues/2599
public void testSubscribingSubscriberAsObserverMaintainsSubscriptionChain() {
TestSubscriber<Object> subscriber = new TestSubscriber<Object>();
Subscription subscription = Observable.just("event").subscribe((Observer<Object>) subscriber);
subscription.unsubscribe();

subscriber.assertUnsubscribed();
}
}