File tree 2 files changed +48
-0
lines changed 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -2095,6 +2095,31 @@ public final Observable<T> toObservable() {
2095
2095
return asObservable (this );
2096
2096
}
2097
2097
2098
+ /**
2099
+ * Returns a {@link Completable} that discards result of the {@link Single} (similar to
2100
+ * {@link Observable#ignoreElements()}) and calls {@code onCompleted} when this source {@link Single} calls
2101
+ * {@code onSuccess}. Error terminal event is propagated.
2102
+ * <p>
2103
+ * <img width="640" height="295" src=
2104
+ * "https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Completable.toCompletable.png"
2105
+ * alt="">
2106
+ * <dl>
2107
+ * <dt><b>Scheduler:</b></dt>
2108
+ * <dd>{@code toCompletable} does not operate by default on a particular {@link Scheduler}.</dd>
2109
+ * </dl>
2110
+ *
2111
+ * @return a {@link Completable} that calls {@code onCompleted} on it's subscriber when the source {@link Single}
2112
+ * calls {@code onSuccess}.
2113
+ * @see <a href="http://reactivex.io/documentation/completable.html">ReactiveX documentation:
2114
+ * Completable</a>.
2115
+ * @since (if this graduates from Experimental/Beta to supported, replace this parenthetical
2116
+ * with the release number).
2117
+ */
2118
+ @ Experimental
2119
+ public final Completable toCompletable () {
2120
+ return Completable .fromSingle (this );
2121
+ }
2122
+
2098
2123
/**
2099
2124
* Returns a Single that mirrors the source Single but applies a timeout policy for its emitted item. If it
2100
2125
* is not emitted within the specified timeout duration, the resulting Single terminates and notifies
Original file line number Diff line number Diff line change @@ -812,6 +812,29 @@ public void testToObservable() {
812
812
ts .assertCompleted ();
813
813
}
814
814
815
+ @ Test
816
+ public void toCompletableSuccess () {
817
+ Completable completable = Single .just ("value" ).toCompletable ();
818
+ TestSubscriber <Object > testSubscriber = new TestSubscriber <Object >();
819
+ completable .subscribe (testSubscriber );
820
+
821
+ testSubscriber .assertCompleted ();
822
+ testSubscriber .assertNoValues ();
823
+ testSubscriber .assertNoErrors ();
824
+ }
825
+
826
+ @ Test
827
+ public void toCompletableError () {
828
+ TestException exception = new TestException ();
829
+ Completable completable = Single .error (exception ).toCompletable ();
830
+ TestSubscriber <Object > testSubscriber = new TestSubscriber <Object >();
831
+ completable .subscribe (testSubscriber );
832
+
833
+ testSubscriber .assertError (exception );
834
+ testSubscriber .assertNoValues ();
835
+ testSubscriber .assertNotCompleted ();
836
+ }
837
+
815
838
@ Test
816
839
public void doOnErrorShouldNotCallActionIfNoErrorHasOccurred () {
817
840
Action1 <Throwable > action = mock (Action1 .class );
You can’t perform that action at this time.
0 commit comments