Skip to content

Commit

Permalink
2.x: Add Single.ignoreElement, deprecate toCompletable (#5957)
Browse files Browse the repository at this point in the history
* 2.x: Add Single.ignoreElement, deprecate toCompletable

* Fix javadoc method name

* Have Single.ignoreElement standard from the start
  • Loading branch information
akarnokd authored Apr 13, 2018
1 parent eee45e0 commit 8690235
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/io/reactivex/Maybe.java
Original file line number Diff line number Diff line change
Expand Up @@ -3084,7 +3084,7 @@ public final Maybe<T> hide() {
/**
* Ignores the item emitted by the source Maybe and only calls {@code onComplete} or {@code onError}.
* <p>
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/ignoreElements.png" alt="">
* <img width="640" height="389" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.ignoreElement.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code ignoreElement} does not operate by default on a particular {@link Scheduler}.</dd>
Expand Down
27 changes: 24 additions & 3 deletions src/main/java/io/reactivex/Single.java
Original file line number Diff line number Diff line change
Expand Up @@ -3491,9 +3491,7 @@ public final <R> R to(Function<? super Single<T>, R> convert) {
* and calls {@code onComplete} when this source {@link Single} calls
* {@code onSuccess}. Error terminal event is propagated.
* <p>
* <img width="640" height="295" src=
* "https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Completable.toCompletable.png"
* alt="">
* <img width="640" height="436" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.toCompletable.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code toCompletable} does not operate by default on a particular {@link Scheduler}.</dd>
Expand All @@ -3503,13 +3501,36 @@ public final <R> R to(Function<? super Single<T>, R> convert) {
* calls {@code onSuccess}.
* @see <a href="http://reactivex.io/documentation/completable.html">ReactiveX documentation: Completable</a>
* @since 2.0
* @deprecated see {@link #ignoreElement()} instead, will be removed in 3.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@Deprecated
public final Completable toCompletable() {
return RxJavaPlugins.onAssembly(new CompletableFromSingle<T>(this));
}

/**
* Returns a {@link Completable} that ignores the success value of this {@link Single}
* and calls {@code onComplete} instead on the returned {@code Completable}.
* <p>
* <img width="640" height="436" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.ignoreElement.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code ignoreElement} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @return a {@link Completable} that calls {@code onComplete} on it's observer when the source {@link Single}
* calls {@code onSuccess}.
* @see <a href="http://reactivex.io/documentation/completable.html">ReactiveX documentation: Completable</a>
* @since 2.1.13
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Completable ignoreElement() {
return RxJavaPlugins.onAssembly(new CompletableFromSingle<T>(this));
}

/**
* Converts this Single into a {@link Flowable}.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public void timeoutOther() throws Exception {
}

@Test
@SuppressWarnings("deprecation")
public void toCompletable() {
Single.just(1)
.toCompletable()
Expand All @@ -266,6 +267,19 @@ public void toCompletable() {
.assertFailure(TestException.class);
}

@Test
public void ignoreElement() {
Single.just(1)
.ignoreElement()
.test()
.assertResult();

Single.error(new TestException())
.ignoreElement()
.test()
.assertFailure(TestException.class);
}

@Test
public void toObservable() {
Single.just(1)
Expand Down

0 comments on commit 8690235

Please sign in to comment.