Skip to content

Commit ba79413

Browse files
authored
2.x: Improve the wording of the Maybe.fromCallable JavaDoc (ReactiveX#5848)
1 parent f624001 commit ba79413

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/main/java/io/reactivex/Maybe.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -628,26 +628,42 @@ public static <T> Maybe<T> fromSingle(SingleSource<T> singleSource) {
628628
}
629629

630630
/**
631-
* Returns a {@link Maybe} that invokes passed function and emits its result for each new MaybeObserver that subscribes
632-
* while considering {@code null} value from the callable as indication for valueless completion.
631+
* Returns a {@link Maybe} that invokes the given {@link Callable} for each individual {@link MaybeObserver} that
632+
* subscribes and emits the resulting non-null item via {@code onSuccess} while
633+
* considering a {@code null} result from the {@code Callable} as indication for valueless completion
634+
* via {@code onComplete}.
633635
* <p>
634-
* Allows you to defer execution of passed function until MaybeObserver subscribes to the {@link Maybe}.
635-
* It makes passed function "lazy".
636-
* Result of the function invocation will be emitted by the {@link Maybe}.
636+
* This operator allows you to defer the execution of the given {@code Callable} until a {@code MaybeObserver}
637+
* subscribes to the returned {@link Maybe}. In other terms, this source operator evaluates the given
638+
* {@code Callable} "lazily".
639+
* <p>
640+
* Note that the {@code null} handling of this operator differs from the similar source operators in the other
641+
* {@link io.reactivex base reactive classes}. Those operators signal a {@code NullPointerException} if the value returned by their
642+
* {@code Callable} is {@code null} while this {@code fromCallable} considers it to indicate the
643+
* returned {@code Maybe} is empty.
637644
* <dl>
638645
* <dt><b>Scheduler:</b></dt>
639646
* <dd>{@code fromCallable} does not operate by default on a particular {@link Scheduler}.</dd>
647+
* <dt><b>Error handling:</b></dt>
648+
* <dd>Any non-fatal exception thrown by {@link Callable#call()} will be forwarded to {@code onError},
649+
* except if the {@code MaybeObserver} disposed the subscription in the meantime. In this latter case,
650+
* the exception is forwarded to the global error handler via
651+
* {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)} wrapped into a
652+
* {@link io.reactivex.exceptions.UndeliverableException UndeliverableException}.
653+
* Fatal exceptions are rethrown and usually will end up in the executing thread's
654+
* {@link java.lang.Thread.UncaughtExceptionHandler#uncaughtException(Thread, Throwable)} handler.</dd>
640655
* </dl>
641656
*
642657
* @param callable
643-
* function which execution should be deferred, it will be invoked when MaybeObserver will subscribe to the {@link Maybe}.
658+
* a {@link Callable} instance whose execution should be deferred and performed for each individual
659+
* {@code MaybeObserver} that subscribes to the returned {@link Maybe}.
644660
* @param <T>
645661
* the type of the item emitted by the {@link Maybe}.
646-
* @return a {@link Maybe} whose {@link MaybeObserver}s' subscriptions trigger an invocation of the given function.
662+
* @return a new Maybe instance
647663
*/
648664
@CheckReturnValue
649665
@SchedulerSupport(SchedulerSupport.NONE)
650-
public static <T> Maybe<T> fromCallable(final Callable<? extends T> callable) {
666+
public static <T> Maybe<T> fromCallable(@NonNull final Callable<? extends T> callable) {
651667
ObjectHelper.requireNonNull(callable, "callable is null");
652668
return RxJavaPlugins.onAssembly(new MaybeFromCallable<T>(callable));
653669
}

0 commit comments

Comments
 (0)