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

Return wrapped Subscription #826

Merged
Merged
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
15 changes: 13 additions & 2 deletions rxjava-core/src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6900,9 +6900,20 @@ public final Subscription subscribe(Subscriber<? super T> observer) {
if (isInternalImplementation(observer)) {
onSubscribeFunction.call(observer);
} else {
onSubscribeFunction.call(new SafeSubscriber<T>(observer));
// assign to `observer` so we return the protected version
observer = new SafeSubscriber<T>(observer);
onSubscribeFunction.call(observer);
}
return hook.onSubscribeReturn(this, observer);
final Subscription returnSubscription = hook.onSubscribeReturn(this, observer);
// we return it inside a Subscription so it can't be cast back to Subscriber
return Subscriptions.create(new Action0() {

@Override
public void call() {
returnSubscription.unsubscribe();
}

});
} catch (OnErrorNotImplementedException e) {
// special handling when onError is not implemented ... we just rethrow
throw e;
Expand Down