-
Notifications
You must be signed in to change notification settings - Fork 184
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
Single
/Completable
subscribe
overloads to handle failures
#3112
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1879,11 +1879,10 @@ protected final void subscribeInternal(Subscriber<? super T> subscriber) { | |
} | ||
|
||
/** | ||
* Subscribe to this {@link Single}, emits the result to the passed {@link Consumer} and log any | ||
* {@link Subscriber#onError(Throwable)}. | ||
* | ||
* @param resultConsumer {@link Consumer} to accept the result of this {@link Single}. | ||
* Subscribe to this {@link Single}, emit the result to the passed {@link Consumer} and log any | ||
* {@link Subscriber#onError(Throwable)} at debug level. | ||
* | ||
* @param resultConsumer {@link Consumer} to accept the result of this {@link Single} if it succeeds. | ||
* @return {@link Cancellable} used to invoke {@link Cancellable#cancel()} on the parameter of | ||
* {@link Subscriber#onSubscribe(Cancellable)} for this {@link Single}. | ||
*/ | ||
|
@@ -1893,6 +1892,21 @@ public final Cancellable subscribe(Consumer<? super T> resultConsumer) { | |
return subscriber; | ||
} | ||
|
||
/** | ||
* Subscribe to this {@link Single}, emit the result or error to one of the passed {@link Consumer}s. | ||
* | ||
* @param resultConsumer {@link Consumer} to accept the result of this {@link Single} if it succeeds. | ||
* @param errorConsumer {@link Consumer} to accept the error of this {@link Single} if it fails. | ||
* @return {@link Cancellable} used to invoke {@link Cancellable#cancel()} on the parameter of | ||
* {@link Subscriber#onSubscribe(Cancellable)} for this {@link Single}. | ||
*/ | ||
public final Cancellable subscribe(Consumer<? super T> resultConsumer, | ||
Consumer<? super Throwable> errorConsumer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to enforce that this helper doesn't receive a null There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, changed ctors to use |
||
SimpleSingleSubscriber<T> subscriber = new SimpleSingleSubscriber<>(resultConsumer, errorConsumer); | ||
subscribeInternal(subscriber); | ||
return subscriber; | ||
} | ||
|
||
/** | ||
* Handles a subscriber to this {@link Single}. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 consumers vs bi-consumer: I picked the way that exists in both rxjava (for Single and Completable) and reactor (for Mono) to be as close as possible to other implementations. We can add
BiConsumer
later if there is an ask.