diff --git a/src/main/java/io/reactivex/rxjava3/core/Single.java b/src/main/java/io/reactivex/rxjava3/core/Single.java index 28177cc9e3..ed676e44fb 100644 --- a/src/main/java/io/reactivex/rxjava3/core/Single.java +++ b/src/main/java/io/reactivex/rxjava3/core/Single.java @@ -20,9 +20,8 @@ import org.reactivestreams.Publisher; import io.reactivex.rxjava3.annotations.*; -import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.disposables.Disposable; -import io.reactivex.rxjava3.exceptions.Exceptions; +import io.reactivex.rxjava3.exceptions.*; import io.reactivex.rxjava3.functions.*; import io.reactivex.rxjava3.internal.functions.*; import io.reactivex.rxjava3.internal.fuseable.*; @@ -43,7 +42,7 @@ * The {@code Single} class implements the Reactive Pattern for a single value response. *
* {@code Single} behaves similarly to {@link Observable} except that it can only emit either a single successful - * value or an error (there is no "onComplete" notification as there is for an {@link Observable}). + * value or an error (there is no {@code onComplete} notification as there is for an {@code Observable}). *
* The {@code Single} class implements the {@link SingleSource} base interface and the default consumer * type it interacts with is the {@link SingleObserver} via the {@link #subscribe(SingleObserver)} method. @@ -68,7 +67,7 @@ *
*
*
- * See {@link Flowable} or {@link Observable} for the + * See {@link Flowable} or {@code Observable} for the * implementation of the Reactive Pattern for a stream or vector of values. *
* For more information see the ReactiveX
@@ -110,14 +109,14 @@
* allow working with a {@code SingleObserver} (or subclass) instance to be applied with in
* a fluent manner (such as in the example above).
* @param
*
*
*
*
*
*
*
*
*
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
- * source SingleSources. The operator buffers the value emitted by these SingleSources and then drains them
- * in order, each one after the previous one completes.
+ * source {@code SingleSource}s. The operator buffers the value emitted by these {@code SingleSource}s and then drains them
+ * in order, each one after the previous one succeeds.
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
- * emitted source Publishers as they are observed. The operator buffers the values emitted by these
- * Publishers and then drains them in order, each one after the previous one completes.
+ * emitted source {@code SingleSource}s as they are observed. The operator buffers the values emitted by these
+ * {@code SingleSource}s and then drains them in order, each one after the previous one succeeds.
*
*
* Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the
- * source SingleSources. The operator buffers the values emitted by these SingleSources and then drains them
- * in order, each one after the previous one completes.
+ * source {@code SingleSource}s. The operator buffers the values emitted by these {@code SingleSource}s and then drains them
+ * in order, each one after the previous one succeeds.
*
*
@@ -512,15 +518,16 @@ public static
*
*
- * Allows you to defer execution of passed function until SingleObserver subscribes to the {@link Single}.
+ * Allows you to defer execution of passed function until {@code SingleObserver} subscribes to the {@code Single}.
* It makes passed function "lazy".
* Result of the function invocation will be emitted by the {@link Single}.
*
@@ -613,7 +624,7 @@ public static
*
- * You can convert any object that supports the {@link Future} interface into a Single that emits the return
- * value of the {@link Future#get} method of that object, by passing the object into the {@code from}
- * method.
+ * The operator calls {@link Future#get()}, which is a blocking method, on the subscription thread.
+ * It is recommended applying {@link #subscribeOn(Scheduler)} to move this blocking wait to a
+ * background thread, and if the {@link Scheduler} supports it, interrupt the wait when the flow
+ * is disposed.
*
- * Important note: This Single is blocking; you cannot dispose it.
+ * A non-{@code null} value is then emitted via {@code onSuccess} or any exception is emitted via
+ * {@code onError}. If the {@code Future} completes with {@code null}, a {@link NullPointerException}
+ * is signaled.
*
*
- * You can convert any object that supports the {@link Future} interface into a {@code Single} that emits
- * the return value of the {@link Future#get} method of that object, by passing the object into the
- * {@code from} method.
*
- * Important note: This {@code Single} is blocking; you cannot dispose it.
+ * The operator calls {@link Future#get(long, TimeUnit)}, which is a blocking method, on the subscription thread.
+ * It is recommended applying {@link #subscribeOn(Scheduler)} to move this blocking wait to a
+ * background thread, and if the {@link Scheduler} supports it, interrupt the wait when the flow
+ * is disposed.
+ *
+ * A non-{@code null} value is then emitted via {@code onSuccess} or any exception is emitted via
+ * {@code onError}. If the {@code Future} completes with {@code null}, a {@link NullPointerException}
+ * is signaled.
*
*
- * You can convert any object that supports the {@link Future} interface into a {@code Single} that emits
+ * You can convert any object that supports the {@code Future} interface into a {@code Single} that emits
* the return value of the {@link Future#get} method of that object, by passing the object into the
* {@code from} method.
*
@@ -717,17 +738,17 @@ public static
*
- * You can convert any object that supports the {@link Future} interface into a {@code Single} that emits
+ * You can convert any object that supports the {@code Future} interface into a {@code Single} that emits
* the return value of the {@link Future#get} method of that object, by passing the object into the
* {@code from} method.
* If the source Publisher is empty, a NoSuchElementException is signalled. If
- * the source has more than one element, an IndexOutOfBoundsException is signalled.
+ * Wraps a specific {@link Publisher} into a {@code Single} and signals its single element or error.
+ *
+ *
- * The {@link Publisher} must follow the
- * Reactive-Streams specification.
+ * If the source {@code Publisher} is empty, a {@link NoSuchElementException} is signaled. If
+ * the source has more than one element, an {@link IndexOutOfBoundsException} is signaled.
+ *
+ * The {@code Publisher} must follow the
+ * Reactive Streams specification.
* Violating the specification may result in undefined behavior.
*
* If possible, use {@link #create(SingleOnSubscribe)} to create a
* source-like {@code Single} instead.
*
- * Note that even though {@link Publisher} appears to be a functional interface, it
+ * Note that even though {@code Publisher} appears to be a functional interface, it
* is not recommended to implement it through a lambda as the specification requires
* state management that is not achievable with a stateless lambda.
- *
- * If the ObservableSource is empty, a NoSuchElementException is signalled.
- * If the source has more than one element, an IndexOutOfBoundsException is signalled.
+ * Wraps a specific {@link ObservableSource} into a {@code Single} and signals its single element or error.
*
*
+ * If the {@code ObservableSource} is empty, a {@link NoSuchElementException} is signaled.
+ * If the source has more than one element, an {@link IndexOutOfBoundsException} is signaled.
*
- * Allows you to defer execution of passed function until SingleObserver subscribes to the {@link Single}.
+ * Allows you to defer execution of passed function until a {@code SingleObserver} subscribes to the {@link Single}.
* It makes passed function "lazy".
* Result of the function invocation will be emitted by the {@link Single}.
*
@@ -852,10 +877,11 @@ public static
*
*
*
*
- * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by
+ * You can combine items emitted by multiple {@code SingleSource}s so that they appear as a single {@code Flowable}, by
* using the {@code merge} method.
*
*
- * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by using
+ * You can combine items emitted by multiple {@code SingleSource}s so that they appear as a single {@code Flowable}, by
* the {@code merge} method.
*
*
- * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by using
+ * You can combine items emitted by multiple {@code SingleSource}s so that they appear as a single {@code Flowable}, by
* the {@code merge} method.
*
* History: 2.1.9 - experimental
* @param
* History: 2.1.9 - experimental
* @param
*
- * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by
+ * You can combine items emitted by multiple {@code SingleSource}s so that they appear as one {@code Flowable}, by
* using the {@code mergeDelayError} method.
* History: 2.1.9 - experimental
* @param
*
- * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by using
+ * You can combine items emitted by multiple {@code SingleSource}s so that they appear as one {@code Flowable}, by
* the {@code mergeDelayError} method.
* History: 2.1.9 - experimental
* @param
*
- * You can combine items emitted by multiple Singles so that they appear as a single Flowable, by using
+ * You can combine items emitted by multiple {@code SingleSource}s so that they appear as one {@code Flowable}, by
* the {@code mergeDelayError} method.
* History: 2.1.9 - experimental
* @param
*
*
*
*
*
*
*
*
- * If the {@code Iterable} of {@link SingleSource}s is empty a {@link NoSuchElementException} error is signalled after subscription.
+ * If the {@code Iterable} of {@code SingleSource}s is empty a {@link NoSuchElementException} error is signaled after subscription.
*
* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the
* implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a
- * {@code Function
*
- * If any of the SingleSources signal an error, all other SingleSources get disposed and the
+ * If any of the {@code SingleSources} signal an error, all other {@code SingleSource}s get disposed and the
* error emitted to downstream immediately.
*
*
*
*
*
*
*
*
*
*
- * If the array of {@link SingleSource}s is empty a {@link NoSuchElementException} error is signalled immediately.
+ * If the array of {@code SingleSource}s is empty a {@link NoSuchElementException} error is signaled immediately.
*
* Note on method signature: since Java doesn't allow creating a generic array with {@code new T[]}, the
* implementation of this operator has to create an {@code Object[]} instead. Unfortunately, a
- * {@code Function
- * If any of the SingleSources signal an error, all other SingleSources get disposed and the
+ * If any of the {@code SingleSource}s signal an error, all other {@code SingleSource}s get disposed and the
* error emitted to downstream immediately.
*
*
*
@@ -126,9 +125,10 @@ public abstract class Single
@@ -151,7 +151,7 @@ public static
*
*
* @param
*
@@ -204,8 +204,9 @@ public static
* @param
*
*
* @param
*
*
* @param
*
@@ -284,10 +287,11 @@ public static
*
* @param callable
- * function which execution should be deferred, it will be invoked when SingleObserver will subscribe to the {@link Single}.
+ * function which execution should be deferred, it will be invoked when {@code SingleObserver} will subscribe to the {@link Single}.
* @param
*
@@ -315,12 +319,13 @@ public static
*
* @param exception
- * the particular Throwable to pass to {@link SingleObserver#onError onError}
+ * the particular {@link Throwable} to pass to {@link SingleObserver#onError onError}
* @param
*
@@ -350,14 +355,15 @@ public static
* @param
*
*
* @param
*
*
* @param
*
*
* @param
*
*
* @param
*
*
* @param
*
@@ -563,9 +571,10 @@ public static
* @param
@@ -586,11 +595,12 @@ public static
*
*
*
* @param future
- * the source {@link Future}
+ * the source {@code Future}
* @param
*
*
*
* @param future
- * the source {@link Future}
+ * the source {@code Future}
* @param timeout
* the maximum time to wait before calling {@code get}
* @param unit
* the {@link TimeUnit} of the {@code timeout} argument
* @param
*
*
*
*
* @param future
- * the source {@link Future}
+ * the source {@code Future}
* @param scheduler
- * the {@link Scheduler} to wait for the Future on. Use a Scheduler such as
- * {@link Schedulers#io()} that can block and wait on the Future
+ * the {@code Scheduler} to wait for the {@code Future} on. Use a {@code Scheduler} such as
+ * {@link Schedulers#io()} that can block and wait on the {@code Future}
* @param
*
*
*
* @param
+ *
*
*
- * @param observableSource the source Observable, not null
+ * @param observableSource the source sequence to wrap, not {@code null}
* @param
*
@@ -906,13 +933,13 @@ public static
* @param
*
@@ -944,13 +972,13 @@ public static
* @param
*
*
*
*
*
*
*
*
*
@@ -1171,8 +1204,9 @@ public static
*
*
@@ -1197,10 +1231,11 @@ public static
*
*
*
*
*
* @param
*
*
- * @param
*
@@ -1355,7 +1393,7 @@ public static
- * @param
*
@@ -1364,7 +1402,7 @@ public static
* @param delay the delay amount
* @param unit the time unit of the delay
- * @return the new Single instance
+ * @return the new {@code Single} instance
* @since 2.0
*/
@CheckReturnValue
@@ -1375,20 +1413,21 @@ public static Single
*
*
* @param delay the delay amount
* @param unit the time unit of the delay
- * @param scheduler the scheduler where the single 0L will be emitted
- * @return the new Single instance
+ * @param scheduler the {@code Scheduler} where the single 0L will be emitted
+ * @return the new {@code Single} instance
* @throws NullPointerException
- * if unit is null, or
- * if scheduler is null
+ * if {@code unit} is {@code null}, or
+ * if {@code scheduler} is {@code null}
* @since 2.0
*/
@CheckReturnValue
@@ -1401,7 +1440,7 @@ public static Single
*
@@ -1409,9 +1448,10 @@ public static Single
* @param
*
@@ -1433,8 +1473,9 @@ public static
* @param
@@ -1460,16 +1501,16 @@ public static
@@ -1490,21 +1531,22 @@ public static
@@ -1533,7 +1575,8 @@ public static
*
*
* @param
*
@@ -1594,17 +1639,18 @@ public static
*
- * @param
*
@@ -1630,20 +1676,21 @@ public static
*
- * @param
*
@@ -1671,23 +1718,24 @@ public static
*
- * @param
*
@@ -1716,26 +1764,28 @@ public static
*
- * @param
*
@@ -1766,29 +1816,31 @@ public static
*
- * @param
*
@@ -1820,32 +1872,34 @@ public static
*
- * @param
*
@@ -1879,35 +1933,37 @@ public static
*
- * @param
*
@@ -1942,38 +1998,41 @@ public static
*
- * @param
*
*
* @param
*
*
- * @param other the other SingleSource to race for the first emission of success or error
- * @return the new Single instance. A subscription to this provided source will occur after subscribing
+ * @param other the other {@code SingleSource} to race for the first emission of success or error
+ * @return the new {@code Single} instance. A subscription to this provided source will occur after subscribing
* to the current source.
+ * @throws NullPointerException if {@code other} is {@code null}
* @since 2.0
*/
@CheckReturnValue
@@ -2063,7 +2124,7 @@ public final Single
@@ -2071,7 +2132,7 @@ public final Single