|
24 | 24 | import io.reactivex.internal.functions.Objects;
|
25 | 25 | import io.reactivex.internal.operators.single.*;
|
26 | 26 | import io.reactivex.internal.subscribers.single.*;
|
| 27 | +import io.reactivex.internal.util.Exceptions; |
27 | 28 | import io.reactivex.plugins.RxJavaPlugins;
|
28 | 29 | import io.reactivex.schedulers.Schedulers;
|
29 | 30 |
|
@@ -60,9 +61,9 @@ public static <T> Single<T> amb(final Iterable<? extends SingleConsumable<? exte
|
60 | 61 | @SuppressWarnings("unchecked")
|
61 | 62 | public static <T> Single<T> amb(final SingleConsumable<? extends T>... sources) {
|
62 | 63 | if (sources.length == 0) {
|
63 |
| - return error(new Supplier<Throwable>() { |
| 64 | + return error(new Callable<Throwable>() { |
64 | 65 | @Override
|
65 |
| - public Throwable get() { |
| 66 | + public Throwable call() { |
66 | 67 | return new NoSuchElementException();
|
67 | 68 | }
|
68 | 69 | });
|
@@ -208,21 +209,21 @@ public static <T> Single<T> create(SingleConsumable<T> onSubscribe) {
|
208 | 209 | return new SingleWrapper<T>(onSubscribe);
|
209 | 210 | }
|
210 | 211 |
|
211 |
| - public static <T> Single<T> defer(final Supplier<? extends SingleConsumable<? extends T>> singleSupplier) { |
| 212 | + public static <T> Single<T> defer(final Callable<? extends SingleConsumable<? extends T>> singleSupplier) { |
212 | 213 | Objects.requireNonNull(singleSupplier, "singleSupplier is null");
|
213 | 214 | return new SingleDefer<T>(singleSupplier);
|
214 | 215 | }
|
215 | 216 |
|
216 |
| - public static <T> Single<T> error(final Supplier<? extends Throwable> errorSupplier) { |
| 217 | + public static <T> Single<T> error(final Callable<? extends Throwable> errorSupplier) { |
217 | 218 | Objects.requireNonNull(errorSupplier, "errorSupplier is null");
|
218 | 219 | return new SingleError<T>(errorSupplier);
|
219 | 220 | }
|
220 | 221 |
|
221 | 222 | public static <T> Single<T> error(final Throwable error) {
|
222 | 223 | Objects.requireNonNull(error, "error is null");
|
223 |
| - return error(new Supplier<Throwable>() { |
| 224 | + return error(new Callable<Throwable>() { |
224 | 225 | @Override
|
225 |
| - public Throwable get() { |
| 226 | + public Throwable call() { |
226 | 227 | return error;
|
227 | 228 | }
|
228 | 229 | });
|
@@ -415,13 +416,13 @@ public static <T> Single<Boolean> equals(final SingleConsumable<? extends T> fir
|
415 | 416 | return new SingleEquals<T>(first, second);
|
416 | 417 | }
|
417 | 418 |
|
418 |
| - public static <T, U> Single<T> using(Supplier<U> resourceSupplier, |
| 419 | + public static <T, U> Single<T> using(Callable<U> resourceSupplier, |
419 | 420 | Function<? super U, ? extends SingleConsumable<? extends T>> singleFunction, Consumer<? super U> disposer) {
|
420 | 421 | return using(resourceSupplier, singleFunction, disposer, true);
|
421 | 422 | }
|
422 | 423 |
|
423 | 424 | public static <T, U> Single<T> using(
|
424 |
| - final Supplier<U> resourceSupplier, |
| 425 | + final Callable<U> resourceSupplier, |
425 | 426 | final Function<? super U, ? extends SingleConsumable<? extends T>> singleFunction,
|
426 | 427 | final Consumer<? super U> disposer,
|
427 | 428 | final boolean eager) {
|
@@ -730,7 +731,7 @@ public final Single<T> observeOn(final Scheduler scheduler) {
|
730 | 731 | return new SingleObserveOn<T>(this, scheduler);
|
731 | 732 | }
|
732 | 733 |
|
733 |
| - public final Single<T> onErrorReturn(final Supplier<? extends T> valueSupplier) { |
| 734 | + public final Single<T> onErrorReturn(final Callable<? extends T> valueSupplier) { |
734 | 735 | Objects.requireNonNull(valueSupplier, "valueSupplier is null");
|
735 | 736 | return new SingleOnErrorReturn<T>(this, valueSupplier, null);
|
736 | 737 | }
|
@@ -858,7 +859,11 @@ private Single<T> timeout0(final long timeout, final TimeUnit unit, final Schedu
|
858 | 859 | }
|
859 | 860 |
|
860 | 861 | public final <R> R to(Function<? super Single<T>, R> convert) {
|
861 |
| - return convert.apply(this); |
| 862 | + try { |
| 863 | + return convert.apply(this); |
| 864 | + } catch (Throwable ex) { |
| 865 | + throw Exceptions.propagate(ex); |
| 866 | + } |
862 | 867 | }
|
863 | 868 |
|
864 | 869 | public final Flowable<T> toFlowable() {
|
|
0 commit comments