Class Completable
- java.lang.Object
-
- io.reactivex.rxjava3.core.Completable
-
- All Implemented Interfaces:
CompletableSource
- Direct Known Subclasses:
CompletableAmb
,CompletableAndThenCompletable
,CompletableCache
,CompletableConcat
,CompletableConcatArray
,CompletableConcatIterable
,CompletableCreate
,CompletableDefer
,CompletableDelay
,CompletableDetach
,CompletableDisposeOn
,CompletableDoFinally
,CompletableDoOnEvent
,CompletableEmpty
,CompletableError
,CompletableErrorSupplier
,CompletableFromAction
,CompletableFromCallable
,CompletableFromCompletionStage
,CompletableFromObservable
,CompletableFromPublisher
,CompletableFromRunnable
,CompletableFromSingle
,CompletableFromSupplier
,CompletableFromUnsafeSource
,CompletableHide
,CompletableLift
,CompletableMerge
,CompletableMergeArray
,CompletableMergeArrayDelayError
,CompletableMergeDelayErrorIterable
,CompletableMergeIterable
,CompletableNever
,CompletableObserveOn
,CompletableOnErrorComplete
,CompletablePeek
,CompletableResumeNext
,CompletableSubject
,CompletableSubscribeOn
,CompletableTakeUntilCompletable
,CompletableTimeout
,CompletableTimer
,CompletableUsing
,FlowableConcatMapCompletable
,FlowableFlatMapCompletableCompletable
,FlowableIgnoreElementsCompletable
,FlowableSwitchMapCompletable
,FlowableSwitchMapCompletablePublisher
,MaybeFlatMapCompletable
,MaybeIgnoreElementCompletable
,ObservableConcatMapCompletable
,ObservableFlatMapCompletableCompletable
,ObservableIgnoreElementsCompletable
,ObservableSwitchMapCompletable
,SchedulerWhen.CreateWorkerFunction.WorkerCompletable
,SingleFlatMapCompletable
public abstract class Completable extends java.lang.Object implements CompletableSource
TheCompletable
class represents a deferred computation without any value but only indication for completion or exception.Completable
behaves similarly toObservable
except that it can only emit either a completion or error signal (there is noonNext
oronSuccess
as with the other reactive types).The
Completable
class implements theCompletableSource
base interface and the default consumer type it interacts with is theCompletableObserver
via thesubscribe(CompletableObserver)
method. TheCompletable
operates with the following sequential protocol:onSubscribe (onError | onComplete)?
Note that as with the
Observable
protocol,onError
andonComplete
are mutually exclusive events.Like
Observable
, a runningCompletable
can be stopped through theDisposable
instance provided to consumers throughCompletableObserver.onSubscribe(io.reactivex.rxjava3.disposables.Disposable)
.Like an
Observable
, aCompletable
is lazy, can be either "hot" or "cold", synchronous or asynchronous.Completable
instances returned by the methods of this class are cold and there is a standard hot implementation in the form of a subject:CompletableSubject
.The documentation for this class makes use of marble diagrams. The following legend explains these diagrams:
See
Flowable
orObservable
for the implementation of the Reactive Pattern for a stream or vector of values.Example:
Disposable d = Completable.complete() .delay(10, TimeUnit.SECONDS, Schedulers.io()) .subscribeWith(new DisposableCompletableObserver() { @Override public void onStart() { System.out.println("Started"); } @Override public void onError(Throwable error) { error.printStackTrace(); } @Override public void onComplete() { System.out.println("Done!"); } }); Thread.sleep(5000); d.dispose();
Note that by design, subscriptions via
subscribe(CompletableObserver)
can't be disposed from the outside (hence thevoid
return of thesubscribe(CompletableObserver)
method) and it is the responsibility of the implementor of theCompletableObserver
to allow this to happen. RxJava supports such usage with the standardDisposableCompletableObserver
instance. For convenience, thesubscribeWith(CompletableObserver)
method is provided as well to allow working with aCompletableObserver
(or subclass) instance to be applied with in a fluent manner (such as in the example above).- See Also:
DisposableCompletableObserver
-
-
Constructor Summary
Constructors Constructor Description Completable()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static @NonNull Completable
amb(@NonNull java.lang.Iterable<? extends CompletableSource> sources)
Returns aCompletable
which terminates as soon as one of the sourceCompletable
s in theIterable
sequence terminates (normally or with an error) and disposes all otherCompletable
s.static @NonNull Completable
ambArray(@NonNull CompletableSource... sources)
Returns aCompletable
which terminates as soon as one of the sourceCompletable
s terminates (normally or with an error) and disposes all otherCompletable
s.@NonNull Completable
ambWith(@NonNull CompletableSource other)
Returns aCompletable
that emits the a terminated event of either thisCompletable
or the otherCompletableSource
, whichever fires first.@NonNull Completable
andThen(@NonNull CompletableSource next)
<@NonNull T>
@NonNull Maybe<T>andThen(@NonNull MaybeSource<@NonNull T> next)
Returns aMaybe
which will subscribe to thisCompletable
and once that is completed then will subscribe to thenext
MaybeSource
.<@NonNull T>
@NonNull Observable<T>andThen(@NonNull ObservableSource<@NonNull T> next)
Returns anObservable
which will subscribe to thisCompletable
and once that is completed then will subscribe to thenext
ObservableSource
.<@NonNull T>
@NonNull Single<T>andThen(@NonNull SingleSource<@NonNull T> next)
Returns aSingle
which will subscribe to thisCompletable
and once that is completed then will subscribe to thenext
SingleSource
.<@NonNull T>
@NonNull Flowable<T>andThen(@NonNull org.reactivestreams.Publisher<@NonNull T> next)
Returns aFlowable
which will subscribe to thisCompletable
and once that is completed then will subscribe to thenext
Publisher
.void
blockingAwait()
Subscribes to and awaits the termination of thisCompletable
instance in a blocking manner and rethrows any exception emitted.boolean
blockingAwait(long timeout, @NonNull java.util.concurrent.TimeUnit unit)
Subscribes to and awaits the termination of thisCompletable
instance in a blocking manner with a specific timeout and rethrows any exception emitted within the timeout window.void
blockingSubscribe()
Subscribes to the currentCompletable
and blocks the current thread until it terminates.void
blockingSubscribe(@NonNull CompletableObserver observer)
Subscribes to the currentCompletable
and calls the appropriateCompletableObserver
method on the current thread.void
blockingSubscribe(@NonNull Action onComplete)
Subscribes to the currentCompletable
and calls givenonComplete
callback on the current thread when it completes normally.void
blockingSubscribe(@NonNull Action onComplete, @NonNull Consumer<? super java.lang.Throwable> onError)
Subscribes to the currentCompletable
and calls the appropriate callback on the current thread when it terminates.@NonNull Completable
cache()
Subscribes to thisCompletable
only once, when the firstCompletableObserver
subscribes to the resultCompletable
, caches its terminal event and relays/replays it to observers.static @NonNull Completable
complete()
Returns aCompletable
instance that completes immediately when subscribed to.@NonNull Completable
compose(@NonNull CompletableTransformer transformer)
Calls the given transformer function with this instance and returns the function's resultingCompletableSource
wrapped withwrap(CompletableSource)
.static @NonNull Completable
concat(@NonNull java.lang.Iterable<? extends CompletableSource> sources)
Returns aCompletable
which completes only when all sources complete, one after another.static @NonNull Completable
concat(@NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
Returns aCompletable
which completes only when all sources complete, one after another.static @NonNull Completable
concat(@NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources, int prefetch)
Returns aCompletable
which completes only when all sources complete, one after another.static @NonNull Completable
concatArray(@NonNull CompletableSource... sources)
Returns aCompletable
which completes only when all sources complete, one after another.static @NonNull Completable
concatArrayDelayError(@NonNull CompletableSource... sources)
Returns aCompletable
which completes only when all sources complete, one after another.static @NonNull Completable
concatDelayError(@NonNull java.lang.Iterable<? extends CompletableSource> sources)
Returns aCompletable
which completes only when all sources complete, one after another.static @NonNull Completable
concatDelayError(@NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
Returns aCompletable
which completes only when all sources complete, one after another.static @NonNull Completable
concatDelayError(@NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources, int prefetch)
Returns aCompletable
which completes only when all sources complete, one after another.@NonNull Completable
concatWith(@NonNull CompletableSource other)
Concatenates thisCompletable
with anotherCompletableSource
.static @NonNull Completable
create(@NonNull CompletableOnSubscribe source)
Provides an API (via a coldCompletable
) that bridges the reactive world with the callback-style world.static @NonNull Completable
defer(@NonNull Supplier<? extends @NonNull CompletableSource> supplier)
Defers the subscription to aCompletable
instance returned by a supplier.@NonNull Completable
delay(long time, @NonNull java.util.concurrent.TimeUnit unit)
Returns aCompletable
which delays the emission of the completion event by the given time.@NonNull Completable
delay(long time, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
Returns aCompletable
which delays the emission of the completion event by the given time while running on the specifiedScheduler
.@NonNull Completable
delay(long time, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler, boolean delayError)
Returns aCompletable
which delays the emission of the completion event, and optionally the error as well, by the given time while running on the specifiedScheduler
.@NonNull Completable
delaySubscription(long time, @NonNull java.util.concurrent.TimeUnit unit)
Returns aCompletable
that delays the subscription to the upstream by a given amount of time.@NonNull Completable
delaySubscription(long time, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
Returns aCompletable
that delays the subscription to the upstream by a given amount of time, both waiting and subscribing on a givenScheduler
.@NonNull Completable
doAfterTerminate(@NonNull Action onAfterTerminate)
Returns aCompletable
instance that calls the givenonAfterTerminate
Action
after thisCompletable
completes normally or with an exception.@NonNull Completable
doFinally(@NonNull Action onFinally)
Calls the specifiedAction
after thisCompletable
signalsonError
oronComplete
or gets disposed by the downstream.@NonNull Completable
doOnComplete(@NonNull Action onComplete)
@NonNull Completable
doOnDispose(@NonNull Action onDispose)
Calls the sharedAction
if aCompletableObserver
subscribed to the currentCompletable
disposes the commonDisposable
it received viaonSubscribe
.@NonNull Completable
doOnError(@NonNull Consumer<? super java.lang.Throwable> onError)
@NonNull Completable
doOnEvent(@NonNull Consumer<? super java.lang.Throwable> onEvent)
Returns aCompletable
which calls the givenonEvent
Consumer
with theThrowable
for anonError
ornull
for anonComplete
signal from thisCompletable
before delivering the signal to the downstream.@NonNull Completable
doOnLifecycle(@NonNull Consumer<? super Disposable> onSubscribe, @NonNull Action onDispose)
Calls the appropriateonXXX
method (shared between allCompletableObserver
s) for the lifecycle events of the sequence (subscription, disposal).private @NonNull Completable
doOnLifecycle(Consumer<? super Disposable> onSubscribe, Consumer<? super java.lang.Throwable> onError, Action onComplete, Action onTerminate, Action onAfterTerminate, Action onDispose)
Returns aCompletable
instance that calls the various callbacks upon the specific lifecycle events.@NonNull Completable
doOnSubscribe(@NonNull Consumer<? super Disposable> onSubscribe)
Returns aCompletable
instance that calls the givenonSubscribe
callback with the disposable that the downstreamCompletableObserver
s receive upon subscription.@NonNull Completable
doOnTerminate(@NonNull Action onTerminate)
Returns aCompletable
instance that calls the givenonTerminate
Action
just before thisCompletable
completes normally or with an exception.static @NonNull Completable
error(@NonNull Supplier<? extends @NonNull java.lang.Throwable> supplier)
Creates aCompletable
which calls the given error supplier for each subscriber and emits its returnedThrowable
.static @NonNull Completable
error(@NonNull java.lang.Throwable throwable)
Creates aCompletable
instance that emits the givenThrowable
exception to subscribers.static @NonNull Completable
fromAction(@NonNull Action action)
Returns aCompletable
instance that runs the givenAction
for eachCompletableObserver
and emits either an exception or simply completes.static @NonNull Completable
fromCallable(@NonNull java.util.concurrent.Callable<?> callable)
Returns aCompletable
which when subscribed, executes theCallable
function, ignores its normal result and emitsonError
oronComplete
only.static @NonNull Completable
fromCompletionStage(@NonNull java.util.concurrent.CompletionStage<?> stage)
Signals completion (or error) when theCompletionStage
terminates.static @NonNull Completable
fromFuture(@NonNull java.util.concurrent.Future<?> future)
Returns aCompletable
instance that reacts to the termination of the givenFuture
in a blocking fashion.static <@NonNull T>
@NonNull CompletablefromMaybe(@NonNull MaybeSource<@NonNull T> maybe)
Returns aCompletable
instance that when subscribed to, subscribes to theMaybeSource
instance and emits anonComplete
event if the maybe emitsonSuccess
/onComplete
or forwards anyonError
events.static <@NonNull T>
@NonNull CompletablefromObservable(@NonNull ObservableSource<@NonNull T> observable)
Returns aCompletable
instance that subscribes to the givenObservableSource
, ignores all values and emits only the terminal event.static <@NonNull T>
@NonNull CompletablefromPublisher(@NonNull org.reactivestreams.Publisher<@NonNull T> publisher)
Returns aCompletable
instance that subscribes to the givenPublisher
, ignores all values and emits only the terminal event.static @NonNull Completable
fromRunnable(@NonNull java.lang.Runnable run)
Returns aCompletable
instance that runs the givenRunnable
for eachCompletableObserver
and emits either its unchecked exception or simply completes.static <@NonNull T>
@NonNull CompletablefromSingle(@NonNull SingleSource<@NonNull T> single)
Returns aCompletable
instance that when subscribed to, subscribes to theSingleSource
instance and emits a completion event if the single emitsonSuccess
or forwards anyonError
events.static @NonNull Completable
fromSupplier(@NonNull Supplier<?> supplier)
Returns aCompletable
which when subscribed, executes theSupplier
function, ignores its normal result and emitsonError
oronComplete
only.@NonNull Completable
hide()
Hides the identity of thisCompletable
and itsDisposable
.@NonNull Completable
lift(@NonNull CompletableOperator onLift)
This method requires advanced knowledge about building operators, please consider other standard composition methods first; Returns aCompletable
which, when subscribed to, invokes theapply(CompletableObserver)
method of the providedCompletableOperator
for each individual downstreamCompletable
and allows the insertion of a custom operator by accessing the downstream'sCompletableObserver
during this subscription phase and providing a newCompletableObserver
, containing the custom operator's intended business logic, that will be used in the subscription process going further upstream.<@NonNull T>
@NonNull Single<Notification<T>>materialize()
Maps the signal types of thisCompletable
into aNotification
of the same kind and emits it as a single success value to downstream.static @NonNull Completable
merge(@NonNull java.lang.Iterable<? extends CompletableSource> sources)
Returns aCompletable
instance that subscribes to all sources at once and completes only when all sourceCompletableSource
s complete or one of them emits an error.static @NonNull Completable
merge(@NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
Returns aCompletable
instance that subscribes to all sources at once and completes only when all sourceCompletableSource
s complete or one of them emits an error.static @NonNull Completable
merge(@NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources, int maxConcurrency)
Returns aCompletable
instance that keeps subscriptions to a limited number of sources at once and completes only when all sourceCompletableSource
s complete or one of them emits an error.private static @NonNull Completable
merge0(@NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources, int maxConcurrency, boolean delayErrors)
Returns aCompletable
instance that keeps subscriptions to a limited number ofCompletableSource
s at once and completes only when all sourceCompletableSource
s terminate in one way or another, combining any exceptions signaled by either the sourcePublisher
or the innerCompletableSource
instances.static @NonNull Completable
mergeArray(@NonNull CompletableSource... sources)
Returns aCompletable
instance that subscribes to all sources at once and completes only when all sourceCompletableSource
s complete or one of them emits an error.static @NonNull Completable
mergeArrayDelayError(@NonNull CompletableSource... sources)
Returns aCompletable
that subscribes to allCompletableSource
s in the source array and delays any error emitted by any of the innerCompletableSource
s until all of them terminate in a way or another.static @NonNull Completable
mergeDelayError(@NonNull java.lang.Iterable<? extends CompletableSource> sources)
Returns aCompletable
that subscribes to allCompletableSource
s in the source sequence and delays any error emitted by any of the innerCompletableSource
s until all of them terminate in a way or another.static @NonNull Completable
mergeDelayError(@NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
Returns aCompletable
that subscribes to allCompletableSource
s in the source sequence and delays any error emitted by either the sourcesPublisher
or any of the innerCompletableSource
s until all of them terminate in a way or another.static @NonNull Completable
mergeDelayError(@NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources, int maxConcurrency)
Returns aCompletable
that subscribes to a limited number of innerCompletableSource
s at once in the source sequence and delays any error emitted by either the sourcesPublisher
or any of the innerCompletableSource
s until all of them terminate in a way or another.@NonNull Completable
mergeWith(@NonNull CompletableSource other)
Returns aCompletable
which subscribes to this and the otherCompletableSource
and completes when both of them complete or one emits an error.static @NonNull Completable
never()
Returns aCompletable
that never callsonError
oronComplete
.@NonNull Completable
observeOn(@NonNull Scheduler scheduler)
Returns aCompletable
which emits the terminal events from the thread of the specifiedScheduler
.@NonNull Completable
onErrorComplete()
Returns aCompletable
instance that if thisCompletable
emits an error, it will emit anonComplete
and swallow the upstreamThrowable
.@NonNull Completable
onErrorComplete(@NonNull Predicate<? super java.lang.Throwable> predicate)
Returns aCompletable
instance that if thisCompletable
emits an error and thePredicate
returnstrue
, it will emit anonComplete
and swallow theThrowable
.@NonNull Completable
onErrorResumeNext(@NonNull Function<? super java.lang.Throwable,? extends CompletableSource> fallbackSupplier)
Returns aCompletable
instance that when encounters an error from thisCompletable
, calls the specifiedmapper
Function
that returns aCompletableSource
instance for it and resumes the execution with it.@NonNull Completable
onErrorResumeWith(@NonNull CompletableSource fallback)
Resumes the flow with the givenCompletableSource
when the currentCompletable
fails instead of signaling the error viaonError
.<@NonNull T>
@NonNull Maybe<T>onErrorReturn(@NonNull Function<? super java.lang.Throwable,? extends @NonNull T> itemSupplier)
Ends the flow with a success item returned by a function for theThrowable
error signaled by the currentCompletable
instead of signaling the error viaonError
.<@NonNull T>
@NonNull Maybe<T>onErrorReturnItem(@NonNull T item)
Ends the flow with the given success item when the currentCompletable
fails instead of signaling the error viaonError
.@NonNull Completable
onTerminateDetach()
Nulls out references to the upstream producer and downstreamCompletableObserver
if the sequence is terminated or downstream callsdispose()
.@NonNull Completable
repeat()
Returns aCompletable
that repeatedly subscribes to thisCompletable
until disposed.@NonNull Completable
repeat(long times)
Returns aCompletable
that subscribes repeatedly at most the given number of times to thisCompletable
.@NonNull Completable
repeatUntil(@NonNull BooleanSupplier stop)
Returns aCompletable
that repeatedly subscribes to thisCompletable
so long as the given stopBooleanSupplier
returnsfalse
.@NonNull Completable
repeatWhen(@NonNull Function<? super Flowable<java.lang.Object>,? extends org.reactivestreams.Publisher<?>> handler)
Returns aCompletable
instance that repeats when thePublisher
returned by the handlerFunction
emits an item or completes when thisPublisher
emits anonComplete
event.@NonNull Completable
retry()
Returns aCompletable
that retries thisCompletable
as long as it emits anonError
event.@NonNull Completable
retry(long times)
Returns aCompletable
that when thisCompletable
emits an error, retries at most the given number of times before giving up and emitting the last error.@NonNull Completable
retry(long times, @NonNull Predicate<? super java.lang.Throwable> predicate)
Returns aCompletable
that when thisCompletable
emits an error, retries at most times or until the predicate returnsfalse
, whichever happens first and emitting the last error.@NonNull Completable
retry(@NonNull BiPredicate<? super java.lang.Integer,? super java.lang.Throwable> predicate)
Returns aCompletable
that retries thisCompletable
in case of an error as long as thepredicate
returnstrue
.@NonNull Completable
retry(@NonNull Predicate<? super java.lang.Throwable> predicate)
Returns aCompletable
that when thisCompletable
emits an error, calls the given predicate with the latestThrowable
to decide whether to resubscribe to the upstream or not.@NonNull Completable
retryUntil(@NonNull BooleanSupplier stop)
Retries until the given stop function returnstrue
.@NonNull Completable
retryWhen(@NonNull Function<? super Flowable<java.lang.Throwable>,? extends org.reactivestreams.Publisher<?>> handler)
Returns aCompletable
which given aPublisher
and when thisCompletable
emits an error, delivers that error through aFlowable
and thePublisher
should signal a value indicating a retry in response or a terminal event indicating a termination.void
safeSubscribe(@NonNull CompletableObserver observer)
Wraps the givenCompletableObserver
, catches anyRuntimeException
s thrown by itsCompletableObserver.onSubscribe(Disposable)
,CompletableObserver.onError(Throwable)
orCompletableObserver.onComplete()
methods and routes those to the global error handler viaRxJavaPlugins.onError(Throwable)
.static @NonNull Single<java.lang.Boolean>
sequenceEqual(@NonNull CompletableSource source1, @NonNull CompletableSource source2)
@NonNull Completable
startWith(@NonNull CompletableSource other)
Returns aCompletable
which first runs the otherCompletableSource
then the currentCompletable
if the other completed normally.<@NonNull T>
@NonNull Flowable<T>startWith(@NonNull MaybeSource<@NonNull T> other)
Returns aFlowable
which first runs the otherMaybeSource
then the currentCompletable
if the other succeeded or completed normally.<@NonNull T>
@NonNull Observable<T>startWith(@NonNull ObservableSource<@NonNull T> other)
Returns anObservable
which first delivers the events of the otherObservableSource
then runs the currentCompletable
.<@NonNull T>
@NonNull Flowable<T>startWith(@NonNull SingleSource<@NonNull T> other)
Returns aFlowable
which first runs the otherSingleSource
then the currentCompletable
if the other succeeded normally.<@NonNull T>
@NonNull Flowable<T>startWith(@NonNull org.reactivestreams.Publisher<@NonNull T> other)
Returns aFlowable
which first delivers the events of the otherPublisher
then runs the currentCompletable
.@NonNull Disposable
subscribe()
Subscribes to thisCompletable
and returns aDisposable
which can be used to dispose the subscription.void
subscribe(@NonNull CompletableObserver observer)
Subscribes the givenCompletableObserver
to thisCompletableSource
instance.@NonNull Disposable
subscribe(@NonNull Action onComplete)
@NonNull Disposable
subscribe(@NonNull Action onComplete, @NonNull Consumer<? super java.lang.Throwable> onError)
Subscribes to thisCompletable
and calls back either theonError
oronComplete
functions.@NonNull Disposable
subscribe(@NonNull Action onComplete, @NonNull Consumer<? super java.lang.Throwable> onError, @NonNull DisposableContainer container)
Wraps the given onXXX callbacks into aDisposable
CompletableObserver
, adds it to the givenDisposableContainer
and ensures, that if the upstream terminates or this particularDisposable
is disposed, theCompletableObserver
is removed from the given composite.protected abstract void
subscribeActual(@NonNull CompletableObserver observer)
Implement this method to handle the incomingCompletableObserver
s and perform the business logic in your operator.@NonNull Completable
subscribeOn(@NonNull Scheduler scheduler)
Returns aCompletable
which subscribes the downstream subscriber on the specified scheduler, making sure the subscription side-effects happen on that specific thread of theScheduler
.<@NonNull E extends CompletableObserver>
EsubscribeWith(@NonNull E observer)
Subscribes a givenCompletableObserver
(subclass) to thisCompletable
and returns the givenCompletableObserver
as is.static @NonNull Completable
switchOnNext(@NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
Switches betweenCompletableSource
s emitted by the sourcePublisher
whenever a newCompletableSource
is emitted, disposing the previously runningCompletableSource
, exposing the setup as aCompletable
sequence.static @NonNull Completable
switchOnNextDelayError(@NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
Switches betweenCompletableSource
s emitted by the sourcePublisher
whenever a newCompletableSource
is emitted, disposing the previously runningCompletableSource
, exposing the setup as aCompletable
sequence and delaying all errors from all of them until all terminate.@NonNull Completable
takeUntil(@NonNull CompletableSource other)
Terminates the downstream if this or the otherCompletable
terminates (wins the termination race) while disposing the connection to the losing source.@NonNull TestObserver<java.lang.Void>
test()
Creates aTestObserver
and subscribes it to thisCompletable
.@NonNull TestObserver<java.lang.Void>
test(boolean dispose)
Creates aTestObserver
optionally in cancelled state, then subscribes it to thisCompletable
.@NonNull Completable
timeout(long timeout, @NonNull java.util.concurrent.TimeUnit unit)
Returns aCompletabl
e that runs thisCompletable
and emits aTimeoutException
in case thisCompletable
doesn't complete within the given time.@NonNull Completable
timeout(long timeout, @NonNull java.util.concurrent.TimeUnit unit, @NonNull CompletableSource fallback)
Returns aCompletable
that runs thisCompletable
and switches to the otherCompletableSource
in case thisCompletable
doesn't complete within the given time.@NonNull Completable
timeout(long timeout, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
Returns aCompletable
that runs thisCompletable
and emits aTimeoutException
in case thisCompletable
doesn't complete within the given time while "waiting" on the specifiedScheduler
.@NonNull Completable
timeout(long timeout, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler, @NonNull CompletableSource fallback)
Returns aCompletable
that runs thisCompletable
and switches to the otherCompletableSource
in case thisCompletable
doesn't complete within the given time while "waiting" on the specifiedScheduler
.private @NonNull Completable
timeout0(long timeout, java.util.concurrent.TimeUnit unit, Scheduler scheduler, CompletableSource fallback)
Returns aCompletable
that runs thisCompletable
and optionally switches to the otherCompletableSource
in case thisCompletable
doesn't complete within the given time while "waiting" on the specifiedScheduler
.static @NonNull Completable
timer(long delay, @NonNull java.util.concurrent.TimeUnit unit)
Returns aCompletable
instance that fires itsonComplete
event after the given delay elapsed.static @NonNull Completable
timer(long delay, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
Returns aCompletable
instance that fires itsonComplete
event after the given delay elapsed by using the suppliedScheduler
.<R> R
to(@NonNull CompletableConverter<? extends R> converter)
Calls the specifiedCompletableConverter
function during assembly time and returns its resulting value.<@Nullable T>
@NonNull java.util.concurrent.CompletionStage<T>toCompletionStage(@Nullable T defaultItem)
Signals the given default item when the upstream completes or signals the upstream error via aCompletionStage
.<@NonNull T>
@NonNull Flowable<T>toFlowable()
Returns aFlowable
which when subscribed to subscribes to thisCompletable
and relays the terminal events to the downstreamSubscriber
.@NonNull java.util.concurrent.Future<java.lang.Void>
toFuture()
Returns aFuture
representing the termination of the currentCompletable
via anull
value.<@NonNull T>
@NonNull Maybe<T>toMaybe()
Converts thisCompletable
into aMaybe
.private static java.lang.NullPointerException
toNpe(java.lang.Throwable ex)
Creates aNullPointerException
instance and sets the givenThrowable
as its initial cause.<@NonNull T>
@NonNull Observable<T>toObservable()
Returns anObservable
which when subscribed to subscribes to thisCompletable
and relays the terminal events to the downstreamObserver
.<@NonNull T>
@NonNull Single<T>toSingle(@NonNull Supplier<? extends @NonNull T> completionValueSupplier)
<@NonNull T>
@NonNull Single<T>toSingleDefault(@NonNull T completionValue)
Converts thisCompletable
into aSingle
which when thisCompletable
completes normally, emits the given value throughonSuccess
.static @NonNull Completable
unsafeCreate(@NonNull CompletableSource onSubscribe)
Constructs aCompletable
instance by wrapping the given source callback without any safeguards; you should manage the lifecycle and response to downstream disposal.@NonNull Completable
unsubscribeOn(@NonNull Scheduler scheduler)
Returns aCompletable
which makes sure when an observer disposes the subscription, thedispose()
method is called on the specifiedScheduler
.static <@NonNull R>
@NonNull Completableusing(@NonNull Supplier<@NonNull R> resourceSupplier, @NonNull Function<? super @NonNull R,? extends CompletableSource> sourceSupplier, @NonNull Consumer<? super @NonNull R> resourceCleanup)
Returns aCompletable
instance which manages a resource along with a customCompletableSource
instance while the subscription is active.static <@NonNull R>
@NonNull Completableusing(@NonNull Supplier<@NonNull R> resourceSupplier, @NonNull Function<? super @NonNull R,? extends CompletableSource> sourceSupplier, @NonNull Consumer<? super @NonNull R> resourceCleanup, boolean eager)
Returns aCompletable
instance which manages a resource along with a customCompletableSource
instance while the subscription is active and performs eager or lazy resource disposition.static @NonNull Completable
wrap(@NonNull CompletableSource source)
-
-
-
Method Detail
-
ambArray
@CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static @NonNull Completable ambArray(@NonNull @NonNull CompletableSource... sources)
Returns aCompletable
which terminates as soon as one of the sourceCompletable
s terminates (normally or with an error) and disposes all otherCompletable
s.- Scheduler:
ambArray
does not operate by default on a particularScheduler
.
- Parameters:
sources
- the array of sourceCompletable
s. A subscription to each source will occur in the same order as in this array.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
amb
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable amb(@NonNull @NonNull java.lang.Iterable<? extends CompletableSource> sources)
Returns aCompletable
which terminates as soon as one of the sourceCompletable
s in theIterable
sequence terminates (normally or with an error) and disposes all otherCompletable
s.- Scheduler:
amb
does not operate by default on a particularScheduler
.
- Parameters:
sources
- theIterable
of sourceCompletable
s. A subscription to each source will occur in the same order as in thisIterable
.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
complete
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable complete()
Returns aCompletable
instance that completes immediately when subscribed to.- Scheduler:
complete
does not operate by default on a particularScheduler
.
- Returns:
- the shared
Completable
instance
-
concatArray
@CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static @NonNull Completable concatArray(@NonNull @NonNull CompletableSource... sources)
Returns aCompletable
which completes only when all sources complete, one after another.- Scheduler:
concatArray
does not operate by default on a particularScheduler
.
- Parameters:
sources
- the sources to concatenate- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concatArrayDelayError
@CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static @NonNull Completable concatArrayDelayError(@NonNull @NonNull CompletableSource... sources)
Returns aCompletable
which completes only when all sources complete, one after another.- Scheduler:
concatArrayDelayError
does not operate by default on a particularScheduler
.
- Parameters:
sources
- the sources to concatenate- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
-
concat
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable concat(@NonNull @NonNull java.lang.Iterable<? extends CompletableSource> sources)
Returns aCompletable
which completes only when all sources complete, one after another.- Scheduler:
concat
does not operate by default on a particularScheduler
.
- Parameters:
sources
- the sources to concatenate- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concat
@CheckReturnValue @SchedulerSupport("none") @BackpressureSupport(FULL) @NonNull public static @NonNull Completable concat(@NonNull @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
Returns aCompletable
which completes only when all sources complete, one after another.- Backpressure:
- The returned
Completable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well. - Scheduler:
concat
does not operate by default on a particularScheduler
.
- Parameters:
sources
- the sources to concatenate- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concat
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public static @NonNull Completable concat(@NonNull @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources, int prefetch)
Returns aCompletable
which completes only when all sources complete, one after another.- Backpressure:
- The returned
Completable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well. - Scheduler:
concat
does not operate by default on a particularScheduler
.
- Parameters:
sources
- the sources to concatenateprefetch
- the number of sources to prefetch from the sources- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifprefetch
is non-positive
-
concatDelayError
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable concatDelayError(@NonNull @NonNull java.lang.Iterable<? extends CompletableSource> sources)
Returns aCompletable
which completes only when all sources complete, one after another.- Scheduler:
concatDelayError
does not operate by default on a particularScheduler
.
- Parameters:
sources
- the sources to concatenate- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
-
concatDelayError
@CheckReturnValue @SchedulerSupport("none") @BackpressureSupport(FULL) @NonNull public static @NonNull Completable concatDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
Returns aCompletable
which completes only when all sources complete, one after another.- Backpressure:
- The returned
Completable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well. - Scheduler:
concatDelayError
does not operate by default on a particularScheduler
.
- Parameters:
sources
- the sources to concatenate- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
-
concatDelayError
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public static @NonNull Completable concatDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources, int prefetch)
Returns aCompletable
which completes only when all sources complete, one after another.- Backpressure:
- The returned
Completable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well. - Scheduler:
concatDelayError
does not operate by default on a particularScheduler
.
- Parameters:
sources
- the sources to concatenateprefetch
- the number of sources to prefetch from the sources- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifprefetch
is non-positive- Since:
- 3.0.0
-
create
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable create(@NonNull @NonNull CompletableOnSubscribe source)
Provides an API (via a coldCompletable
) that bridges the reactive world with the callback-style world.Example:
Completable.create(emitter -> { Callback listener = new Callback() { @Override public void onEvent(Event e) { emitter.onComplete(); } @Override public void onFailure(Exception e) { emitter.onError(e); } }; AutoCloseable c = api.someMethod(listener); emitter.setCancellable(c::close); });
Whenever a
CompletableObserver
subscribes to the returnedCompletable
, the providedCompletableOnSubscribe
callback is invoked with a fresh instance of aCompletableEmitter
that will interact only with that specificCompletableObserver
. If thisCompletableObserver
disposes the flow (makingCompletableEmitter.isDisposed()
returntrue
), other observers subscribed to the same returnedCompletable
are not affected.- Scheduler:
create
does not operate by default on a particularScheduler
.
- Parameters:
source
- the emitter that is called when aCompletableObserver
subscribes to the returnedCompletable
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsource
isnull
- See Also:
CompletableOnSubscribe
,Cancellable
-
sequenceEqual
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Single<java.lang.Boolean> sequenceEqual(@NonNull @NonNull CompletableSource source1, @NonNull @NonNull CompletableSource source2)
Compares twoCompletableSource
s and emitstrue
via aSingle
if both complete.- Scheduler:
sequenceEqual
does not operate by default on a particularScheduler
.
- Parameters:
source1
- the firstCompletableSource
instancesource2
- the secondCompletableSource
instance- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifsource1
orsource2
isnull
- Since:
- 3.0.0
-
unsafeCreate
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable unsafeCreate(@NonNull @NonNull CompletableSource onSubscribe)
Constructs aCompletable
instance by wrapping the given source callback without any safeguards; you should manage the lifecycle and response to downstream disposal.- Scheduler:
unsafeCreate
does not operate by default on a particularScheduler
.
- Parameters:
onSubscribe
- the callback which will receive theCompletableObserver
instances when theCompletable
is subscribed to.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifonSubscribe
isnull
java.lang.IllegalArgumentException
- ifsource
is aCompletable
-
defer
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable defer(@NonNull @NonNull Supplier<? extends @NonNull CompletableSource> supplier)
Defers the subscription to aCompletable
instance returned by a supplier.- Scheduler:
defer
does not operate by default on a particularScheduler
.
- Parameters:
supplier
- the supplier that returns theCompletable
that will be subscribed to.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsupplier
isnull
-
error
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable error(@NonNull @NonNull Supplier<? extends @NonNull java.lang.Throwable> supplier)
Creates aCompletable
which calls the given error supplier for each subscriber and emits its returnedThrowable
.If the
errorSupplier
returnsnull
, the downstreamCompletableObserver
s will receive aNullPointerException
.- Scheduler:
error
does not operate by default on a particularScheduler
.
- Parameters:
supplier
- the error supplier, notnull
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsupplier
isnull
-
error
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable error(@NonNull @NonNull java.lang.Throwable throwable)
Creates aCompletable
instance that emits the givenThrowable
exception to subscribers.- Scheduler:
error
does not operate by default on a particularScheduler
.
- Parameters:
throwable
- theThrowable
instance to emit, notnull
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifthrowable
isnull
-
fromAction
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable fromAction(@NonNull @NonNull Action action)
Returns aCompletable
instance that runs the givenAction
for eachCompletableObserver
and emits either an exception or simply completes.- Scheduler:
fromAction
does not operate by default on a particularScheduler
.- Error handling:
- If the
Action
throws an exception, the respectiveThrowable
is delivered to the downstream viaCompletableObserver.onError(Throwable)
, except when the downstream has disposed thisCompletable
source. In this latter case, theThrowable
is delivered to the global error handler viaRxJavaPlugins.onError(Throwable)
as anUndeliverableException
.
- Parameters:
action
- theAction
to run for each subscribingCompletableObserver
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifaction
isnull
-
fromCallable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable fromCallable(@NonNull @NonNull java.util.concurrent.Callable<?> callable)
Returns aCompletable
which when subscribed, executes theCallable
function, ignores its normal result and emitsonError
oronComplete
only.- Scheduler:
fromCallable
does not operate by default on a particularScheduler
.- Error handling:
- If the
Callable
throws an exception, the respectiveThrowable
is delivered to the downstream viaCompletableObserver.onError(Throwable)
, except when the downstream has disposed thisCompletable
source. In this latter case, theThrowable
is delivered to the global error handler viaRxJavaPlugins.onError(Throwable)
as anUndeliverableException
.
- Parameters:
callable
- theCallable
instance to execute for each subscribingCompletableObserver
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifcallable
isnull
- See Also:
defer(Supplier)
,fromSupplier(Supplier)
-
fromFuture
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable fromFuture(@NonNull @NonNull java.util.concurrent.Future<?> future)
Returns aCompletable
instance that reacts to the termination of the givenFuture
in a blocking fashion.Note that disposing the
Completable
won't cancel theFuture
. UsedoOnDispose(Action)
and callFuture.cancel(boolean)
in theAction
.- Scheduler:
fromFuture
does not operate by default on a particularScheduler
.
- Parameters:
future
- theFuture
to react to- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- iffuture
isnull
- See Also:
fromCompletionStage(CompletionStage)
-
fromMaybe
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Completable fromMaybe(@NonNull @NonNull MaybeSource<@NonNull T> maybe)
Returns aCompletable
instance that when subscribed to, subscribes to theMaybeSource
instance and emits anonComplete
event if the maybe emitsonSuccess
/onComplete
or forwards anyonError
events.- Scheduler:
fromMaybe
does not operate by default on a particularScheduler
.
History: 2.1.17 - beta
- Type Parameters:
T
- the value type of theMaybeSource
element- Parameters:
maybe
- theMaybeSource
instance to subscribe to, notnull
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifmaybe
isnull
- Since:
- 2.2
-
fromRunnable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable fromRunnable(@NonNull @NonNull java.lang.Runnable run)
Returns aCompletable
instance that runs the givenRunnable
for eachCompletableObserver
and emits either its unchecked exception or simply completes.If the code to be wrapped needs to throw a checked or more broader
Throwable
exception, that exception has to be converted to an unchecked exception by the wrapped code itself. Alternatively, use thefromAction(Action)
method which allows the wrapped code to throw anyThrowable
exception and will signal it to observers as-is.- Scheduler:
fromRunnable
does not operate by default on a particularScheduler
.- Error handling:
- If the
Runnable
throws an exception, the respectiveThrowable
is delivered to the downstream viaCompletableObserver.onError(Throwable)
, except when the downstream has disposed thisCompletable
source. In this latter case, theThrowable
is delivered to the global error handler viaRxJavaPlugins.onError(Throwable)
as anUndeliverableException
.
- Parameters:
run
- theRunnable
to run for eachCompletableObserver
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifrun
isnull
- See Also:
fromAction(Action)
-
fromObservable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Completable fromObservable(@NonNull @NonNull ObservableSource<@NonNull T> observable)
Returns aCompletable
instance that subscribes to the givenObservableSource
, ignores all values and emits only the terminal event.- Scheduler:
fromObservable
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of theObservableSource
- Parameters:
observable
- theObservableSource
instance to subscribe to, notnull
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifobservable
isnull
-
fromPublisher
@CheckReturnValue @NonNull @BackpressureSupport(UNBOUNDED_IN) @SchedulerSupport("none") public static <@NonNull T> @NonNull Completable fromPublisher(@NonNull @NonNull org.reactivestreams.Publisher<@NonNull T> publisher)
Returns aCompletable
instance that subscribes to the givenPublisher
, ignores all values and emits only the terminal event.The
Publisher
must follow the Reactive-Streams specification. Violating the specification may result in undefined behavior.If possible, use
create(CompletableOnSubscribe)
to create a source-likeCompletable
instead.Note that even though
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.- Backpressure:
- The returned
Completable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well. - Scheduler:
fromPublisher
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of thePublisher
- Parameters:
publisher
- thePublisher
instance to subscribe to, notnull
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifpublisher
isnull
- See Also:
create(CompletableOnSubscribe)
-
fromSingle
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Completable fromSingle(@NonNull @NonNull SingleSource<@NonNull T> single)
Returns aCompletable
instance that when subscribed to, subscribes to theSingleSource
instance and emits a completion event if the single emitsonSuccess
or forwards anyonError
events.- Scheduler:
fromSingle
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type of theSingleSource
- Parameters:
single
- theSingleSource
instance to subscribe to, notnull
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsingle
isnull
-
fromSupplier
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable fromSupplier(@NonNull @NonNull Supplier<?> supplier)
Returns aCompletable
which when subscribed, executes theSupplier
function, ignores its normal result and emitsonError
oronComplete
only.- Scheduler:
fromSupplier
does not operate by default on a particularScheduler
.- Error handling:
- If the
Supplier
throws an exception, the respectiveThrowable
is delivered to the downstream viaCompletableObserver.onError(Throwable)
, except when the downstream has disposed thisCompletable
source. In this latter case, theThrowable
is delivered to the global error handler viaRxJavaPlugins.onError(Throwable)
as anUndeliverableException
.
- Parameters:
supplier
- theSupplier
instance to execute for eachCompletableObserver
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsupplier
isnull
- Since:
- 3.0.0
- See Also:
defer(Supplier)
,fromCallable(Callable)
-
mergeArray
@CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static @NonNull Completable mergeArray(@NonNull @NonNull CompletableSource... sources)
Returns aCompletable
instance that subscribes to all sources at once and completes only when all sourceCompletableSource
s complete or one of them emits an error.- Scheduler:
mergeArray
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
CompletableSource
s signal aThrowable
viaonError
, the resultingCompletable
terminates with thatThrowable
and all other sourceCompletableSource
s are disposed. If more than oneCompletableSource
signals an error, the resultingCompletable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedCompletable
has been disposed or terminated with a (composite) error will be sent to the same global error handler. UsemergeArrayDelayError(CompletableSource...)
to merge sources and terminate only when all sourceCompletableSource
s have completed or failed with an error.
- Parameters:
sources
- the array ofCompletableSource
s.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- See Also:
mergeArrayDelayError(CompletableSource...)
-
merge
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable merge(@NonNull @NonNull java.lang.Iterable<? extends CompletableSource> sources)
Returns aCompletable
instance that subscribes to all sources at once and completes only when all sourceCompletableSource
s complete or one of them emits an error.- Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
CompletableSource
s signal aThrowable
viaonError
, the resultingCompletable
terminates with thatThrowable
and all other sourceCompletableSource
s are disposed. If more than oneCompletableSource
signals an error, the resultingCompletable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedCompletable
has been disposed or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(Iterable)
to merge sources and terminate only when all sourceCompletableSource
s have completed or failed with an error.
- Parameters:
sources
- theIterable
sequence ofCompletableSource
s.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- See Also:
mergeDelayError(Iterable)
-
merge
@CheckReturnValue @SchedulerSupport("none") @BackpressureSupport(UNBOUNDED_IN) @NonNull public static @NonNull Completable merge(@NonNull @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
Returns aCompletable
instance that subscribes to all sources at once and completes only when all sourceCompletableSource
s complete or one of them emits an error.- Backpressure:
- The operator consumes the given
Publisher
in an unbounded manner (requestingLong.MAX_VALUE
upfront). - Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
CompletableSource
s signal aThrowable
viaonError
, the resultingCompletable
terminates with thatThrowable
and all other sourceCompletableSource
s are disposed. If more than oneCompletableSource
signals an error, the resultingCompletable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedCompletable
has been disposed or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(Publisher)
to merge sources and terminate only when all sourceCompletableSource
s have completed or failed with an error.
- Parameters:
sources
- thePublisher
sequence ofCompletableSource
s.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- See Also:
mergeDelayError(Publisher)
-
merge
@CheckReturnValue @SchedulerSupport("none") @BackpressureSupport(FULL) @NonNull public static @NonNull Completable merge(@NonNull @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources, int maxConcurrency)
Returns aCompletable
instance that keeps subscriptions to a limited number of sources at once and completes only when all sourceCompletableSource
s complete or one of them emits an error.- Backpressure:
- The operator consumes the given
Publisher
in a bounded manner, requestingmaxConcurrency
items first, then keeps requesting as many more as the innerCompletableSource
s terminate. - Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
CompletableSource
s signal aThrowable
viaonError
, the resultingCompletable
terminates with thatThrowable
and all other sourceCompletableSource
s are disposed. If more than oneCompletableSource
signals an error, the resultingCompletable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedCompletable
has been disposed or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(Publisher, int)
to merge sources and terminate only when all sourceCompletableSource
s have completed or failed with an error.
- Parameters:
sources
- thePublisher
sequence ofCompletableSource
s.maxConcurrency
- the maximum number of concurrent subscriptions- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifmaxConcurrency
is less than 1- See Also:
mergeDelayError(Publisher, int)
-
merge0
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) private static @NonNull Completable merge0(@NonNull @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources, int maxConcurrency, boolean delayErrors)
Returns aCompletable
instance that keeps subscriptions to a limited number ofCompletableSource
s at once and completes only when all sourceCompletableSource
s terminate in one way or another, combining any exceptions signaled by either the sourcePublisher
or the innerCompletableSource
instances.- Backpressure:
- The operator consumes the given
Publisher
in a bounded manner, requestingmaxConcurrency
items first, then keeps requesting as many more as the innerCompletableSource
s terminate. - Scheduler:
merge0
does not operate by default on a particularScheduler
.
- Parameters:
sources
- thePublisher
sequence ofCompletableSource
s.maxConcurrency
- the maximum number of concurrent subscriptionsdelayErrors
- delay all errors from the main source and from the innerCompletableSource
s?- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifmaxConcurrency
is less than 1
-
mergeArrayDelayError
@CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static @NonNull Completable mergeArrayDelayError(@NonNull @NonNull CompletableSource... sources)
Returns aCompletable
that subscribes to allCompletableSource
s in the source array and delays any error emitted by any of the innerCompletableSource
s until all of them terminate in a way or another.- Scheduler:
mergeArrayDelayError
does not operate by default on a particularScheduler
.
- Parameters:
sources
- the array ofCompletableSource
s- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
mergeDelayError
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable mergeDelayError(@NonNull @NonNull java.lang.Iterable<? extends CompletableSource> sources)
Returns aCompletable
that subscribes to allCompletableSource
s in the source sequence and delays any error emitted by any of the innerCompletableSource
s until all of them terminate in a way or another.- Scheduler:
mergeDelayError
does not operate by default on a particularScheduler
.
- Parameters:
sources
- the sequence ofCompletableSource
s- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
mergeDelayError
@CheckReturnValue @SchedulerSupport("none") @BackpressureSupport(UNBOUNDED_IN) @NonNull public static @NonNull Completable mergeDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
Returns aCompletable
that subscribes to allCompletableSource
s in the source sequence and delays any error emitted by either the sourcesPublisher
or any of the innerCompletableSource
s until all of them terminate in a way or another.- Backpressure:
- The operator consumes the
Publisher
in an unbounded manner (requestingLong.MAX_VALUE
from it). - Scheduler:
mergeDelayError
does not operate by default on a particularScheduler
.
- Parameters:
sources
- the sequence ofCompletableSource
s- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
mergeDelayError
@CheckReturnValue @SchedulerSupport("none") @BackpressureSupport(FULL) @NonNull public static @NonNull Completable mergeDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources, int maxConcurrency)
Returns aCompletable
that subscribes to a limited number of innerCompletableSource
s at once in the source sequence and delays any error emitted by either the sourcesPublisher
or any of the innerCompletableSource
s until all of them terminate in a way or another.- Backpressure:
- The operator requests
maxConcurrency
items from thePublisher
upfront and keeps requesting as many more as many innerCompletableSource
s terminate. - Scheduler:
mergeDelayError
does not operate by default on a particularScheduler
.
- Parameters:
sources
- the sequence ofCompletableSource
smaxConcurrency
- the maximum number of concurrent subscriptions to have at a time to the innerCompletableSource
s- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifmaxConcurrency
is non-positive
-
never
@CheckReturnValue @SchedulerSupport("none") @NonNull public static @NonNull Completable never()
Returns aCompletable
that never callsonError
oronComplete
.- Scheduler:
never
does not operate by default on a particularScheduler
.
- Returns:
- the singleton instance that never calls
onError
oronComplete
-
timer
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public static @NonNull Completable timer(long delay, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Returns aCompletable
instance that fires itsonComplete
event after the given delay elapsed.- Scheduler:
timer
does operate by default on thecomputation
Scheduler
.
- Parameters:
delay
- the delay timeunit
- the delay unit- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
-
timer
@CheckReturnValue @NonNull @SchedulerSupport("custom") public static @NonNull Completable timer(long delay, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Returns aCompletable
instance that fires itsonComplete
event after the given delay elapsed by using the suppliedScheduler
.- Scheduler:
timer
operates on theScheduler
you specify.
- Parameters:
delay
- the delay timeunit
- the delay unitscheduler
- theScheduler
where to emit theonComplete
event- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
-
toNpe
private static java.lang.NullPointerException toNpe(java.lang.Throwable ex)
Creates aNullPointerException
instance and sets the givenThrowable
as its initial cause.- Parameters:
ex
- theThrowable
instance to use as cause, notnull
(not verified)- Returns:
- the new
NullPointerException
-
switchOnNext
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(UNBOUNDED_IN) public static @NonNull Completable switchOnNext(@NonNull @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
Switches betweenCompletableSource
s emitted by the sourcePublisher
whenever a newCompletableSource
is emitted, disposing the previously runningCompletableSource
, exposing the setup as aCompletable
sequence.- Backpressure:
- The
sources
Publisher
is consumed in an unbounded manner (requestingLong.MAX_VALUE
). - Scheduler:
switchOnNext
does not operate by default on a particularScheduler
.- Error handling:
- The returned sequence fails with the first error signaled by the
sources
Publisher
or the currently runningCompletableSource
, disposing the rest. Late errors are forwarded to the global error handler viaRxJavaPlugins.onError(Throwable)
.
- Parameters:
sources
- thePublisher
sequence of innerCompletableSource
s to switch between- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
- See Also:
switchOnNextDelayError(Publisher)
, ReactiveX operators documentation: Switch
-
switchOnNextDelayError
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(UNBOUNDED_IN) public static @NonNull Completable switchOnNextDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends CompletableSource> sources)
Switches betweenCompletableSource
s emitted by the sourcePublisher
whenever a newCompletableSource
is emitted, disposing the previously runningCompletableSource
, exposing the setup as aCompletable
sequence and delaying all errors from all of them until all terminate.- Backpressure:
- The
sources
Publisher
is consumed in an unbounded manner (requestingLong.MAX_VALUE
). - Scheduler:
switchOnNextDelayError
does not operate by default on a particularScheduler
.- Error handling:
- The returned
Completable
collects all errors emitted by either thesources
Publisher
or any innerCompletableSource
and emits them as aCompositeException
when all sources terminate. If only one source ever failed, its error is emitted as-is at the end.
- Parameters:
sources
- thePublisher
sequence of innerCompletableSource
s to switch between- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
- See Also:
switchOnNext(Publisher)
, ReactiveX operators documentation: Switch
-
using
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull R> @NonNull Completable using(@NonNull @NonNull Supplier<@NonNull R> resourceSupplier, @NonNull @NonNull Function<? super @NonNull R,? extends CompletableSource> sourceSupplier, @NonNull @NonNull Consumer<? super @NonNull R> resourceCleanup)
Returns aCompletable
instance which manages a resource along with a customCompletableSource
instance while the subscription is active.This overload disposes eagerly before the terminal event is emitted.
- Scheduler:
using
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the resource type- Parameters:
resourceSupplier
- theSupplier
that returns a resource to be managed.sourceSupplier
- theFunction
that given a resource returns aCompletableSource
instance that will be subscribed toresourceCleanup
- theConsumer
that disposes the resource created by the resource supplier- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifresourceSupplier
,sourceSupplier
orresourceCleanup
isnull
-
using
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull R> @NonNull Completable using(@NonNull @NonNull Supplier<@NonNull R> resourceSupplier, @NonNull @NonNull Function<? super @NonNull R,? extends CompletableSource> sourceSupplier, @NonNull @NonNull Consumer<? super @NonNull R> resourceCleanup, boolean eager)
Returns aCompletable
instance which manages a resource along with a customCompletableSource
instance while the subscription is active and performs eager or lazy resource disposition.If this overload performs a lazy disposal after the terminal event is emitted. The exceptions thrown at this time will be delivered to the global
RxJavaPlugins.onError(Throwable)
handler only.- Scheduler:
using
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the resource type- Parameters:
resourceSupplier
- theSupplier
that returns a resource to be managedsourceSupplier
- theFunction
that given a resource returns a non-null
CompletableSource
instance that will be subscribed toresourceCleanup
- theConsumer
that disposes the resource created by the resource suppliereager
- Iftrue
then resource disposal will happen either on adispose()
call before the upstream is disposed or just before the emission of a terminal event (onComplete
oronError
). Iffalse
the resource disposal will happen either on adispose()
call after the upstream is disposed or just after the emission of a terminal event (onComplete
oronError
).- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifresourceSupplier
,sourceSupplier
orresourceCleanup
isnull
-
wrap
@CheckReturnValue @NonNull @SchedulerSupport("none") public static @NonNull Completable wrap(@NonNull @NonNull CompletableSource source)
Wraps the givenCompletableSource
into aCompletable
if not alreadyCompletable
.- Scheduler:
wrap
does not operate by default on a particularScheduler
.
- Parameters:
source
- the source to wrap- Returns:
- the new wrapped or cast
Completable
instance - Throws:
java.lang.NullPointerException
- ifsource
isnull
-
ambWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable ambWith(@NonNull @NonNull CompletableSource other)
Returns aCompletable
that emits the a terminated event of either thisCompletable
or the otherCompletableSource
, whichever fires first.- Scheduler:
ambWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherCompletableSource
, notnull
. A subscription to this provided source will occur after subscribing to the current source.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
-
andThen
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull T> @NonNull Observable<T> andThen(@NonNull @NonNull ObservableSource<@NonNull T> next)
Returns anObservable
which will subscribe to thisCompletable
and once that is completed then will subscribe to thenext
ObservableSource
. An error event from thisCompletable
will be propagated to the downstream observer and will result in skipping the subscription to the nextObservableSource
.- Scheduler:
andThen
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type of the nextObservableSource
- Parameters:
next
- theObservableSource
to subscribe after thisCompletable
is completed, notnull
- Returns:
- the new
Observable
that composes thisCompletable
and the nextObservableSource
- Throws:
java.lang.NullPointerException
- ifnext
isnull
-
andThen
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public final <@NonNull T> @NonNull Flowable<T> andThen(@NonNull @NonNull org.reactivestreams.Publisher<@NonNull T> next)
Returns aFlowable
which will subscribe to thisCompletable
and once that is completed then will subscribe to thenext
Publisher
. An error event from thisCompletable
will be propagated to the downstream subscriber and will result in skipping the subscription to the nextPublisher
.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well. - Scheduler:
andThen
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type of the nextPublisher
- Parameters:
next
- thePublisher
to subscribe after thisCompletable
is completed, notnull
- Returns:
- the new
Flowable
that composes thisCompletable
and the nextPublisher
- Throws:
java.lang.NullPointerException
- ifnext
isnull
-
andThen
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull T> @NonNull Single<T> andThen(@NonNull @NonNull SingleSource<@NonNull T> next)
Returns aSingle
which will subscribe to thisCompletable
and once that is completed then will subscribe to thenext
SingleSource
. An error event from thisCompletable
will be propagated to the downstream observer and will result in skipping the subscription to the nextSingleSource
.- Scheduler:
andThen
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type of the nextSingleSource
- Parameters:
next
- theSingleSource
to subscribe after thisCompletable
is completed, notnull
- Returns:
- the new
Single
that composes thisCompletable
and the nextSingleSource
- Throws:
java.lang.NullPointerException
- ifnext
isnull
-
andThen
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull T> @NonNull Maybe<T> andThen(@NonNull @NonNull MaybeSource<@NonNull T> next)
Returns aMaybe
which will subscribe to thisCompletable
and once that is completed then will subscribe to thenext
MaybeSource
. An error event from thisCompletable
will be propagated to the downstream observer and will result in skipping the subscription to the nextMaybeSource
.- Scheduler:
andThen
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type of the nextMaybeSource
- Parameters:
next
- theMaybeSource
to subscribe after thisCompletable
is completed, notnull
- Returns:
- the new
Maybe
that composes thisCompletable
and the nextMaybeSource
- Throws:
java.lang.NullPointerException
- ifnext
isnull
-
andThen
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable andThen(@NonNull @NonNull CompletableSource next)
Returns aCompletable
that first runs thisCompletable
and then the otherCompletableSource
. An error event from thisCompletable
will be propagated to the downstream observer and will result in skipping the subscription to the nextCompletableSource
.This is an alias for
concatWith(CompletableSource)
.- Scheduler:
andThen
does not operate by default on a particularScheduler
.
- Parameters:
next
- the otherCompletableSource
, notnull
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifnext
isnull
-
blockingAwait
@SchedulerSupport("none") public final void blockingAwait()
Subscribes to and awaits the termination of thisCompletable
instance in a blocking manner and rethrows any exception emitted.- Scheduler:
blockingAwait
does not operate by default on a particularScheduler
.- Error handling:
- If the source signals an error, the operator wraps a checked
Exception
intoRuntimeException
and throws that. Otherwise,RuntimeException
s andError
s are rethrown as they are.
- Throws:
java.lang.RuntimeException
- wrapping anInterruptedException
if the current thread is interrupted
-
blockingAwait
@CheckReturnValue @SchedulerSupport("none") public final boolean blockingAwait(long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Subscribes to and awaits the termination of thisCompletable
instance in a blocking manner with a specific timeout and rethrows any exception emitted within the timeout window.- Scheduler:
blockingAwait
does not operate by default on a particularScheduler
.- Error handling:
- If the source signals an error, the operator wraps a checked
Exception
intoRuntimeException
and throws that. Otherwise,RuntimeException
s andError
s are rethrown as they are.
- Parameters:
timeout
- the timeout valueunit
- the timeout unit- Returns:
true
if the thisCompletable
instance completed normally within the time limit,false
if the timeout elapsed before thisCompletable
terminated.- Throws:
java.lang.RuntimeException
- wrapping anInterruptedException
if the current thread is interruptedjava.lang.NullPointerException
- ifunit
isnull
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe()
Subscribes to the currentCompletable
and blocks the current thread until it terminates.- Scheduler:
blockingSubscribe
does not operate by default on a particularScheduler
.- Error handling:
- If the current
Completable
signals an error, theThrowable
is routed to the global error handler viaRxJavaPlugins.onError(Throwable)
. If the current thread is interrupted, anInterruptedException
is routed to the same global error handler.
- Since:
- 3.0.0
- See Also:
blockingSubscribe(Action)
,blockingSubscribe(Action, Consumer)
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Action onComplete)
Subscribes to the currentCompletable
and calls givenonComplete
callback on the current thread when it completes normally.- Scheduler:
blockingSubscribe
does not operate by default on a particularScheduler
.- Error handling:
- If either the current
Completable
signals an error oronComplete
throws, the respectiveThrowable
is routed to the global error handler viaRxJavaPlugins.onError(Throwable)
. If the current thread is interrupted, anInterruptedException
is routed to the same global error handler.
- Parameters:
onComplete
- theAction
to call if the currentCompletable
completes normally- Throws:
java.lang.NullPointerException
- ifonComplete
isnull
- Since:
- 3.0.0
- See Also:
blockingSubscribe(Action, Consumer)
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Action onComplete, @NonNull @NonNull Consumer<? super java.lang.Throwable> onError)
Subscribes to the currentCompletable
and calls the appropriate callback on the current thread when it terminates.- Scheduler:
blockingSubscribe
does not operate by default on a particularScheduler
.- Error handling:
- If either
onComplete
oronError
throw, theThrowable
is routed to the global error handler viaRxJavaPlugins.onError(Throwable)
. If the current thread is interrupted, theonError
consumer is called with anInterruptedException
.
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull CompletableObserver observer)
Subscribes to the currentCompletable
and calls the appropriateCompletableObserver
method on the current thread.- Scheduler:
blockingSubscribe
does not operate by default on a particularScheduler
.- Error handling:
- An
onError
signal is delivered to theCompletableObserver.onError(Throwable)
method. If any of theCompletableObserver
's methods throw, theRuntimeException
is propagated to the caller of this method. If the current thread is interrupted, anInterruptedException
is delivered toobserver.onError
.
- Parameters:
observer
- theCompletableObserver
to call methods on the current thread- Throws:
java.lang.NullPointerException
- ifobserver
isnull
- Since:
- 3.0.0
-
cache
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable cache()
Subscribes to thisCompletable
only once, when the firstCompletableObserver
subscribes to the resultCompletable
, caches its terminal event and relays/replays it to observers.Note that this operator doesn't allow disposing the connection of the upstream source.
- Scheduler:
cache
does not operate by default on a particularScheduler
.
History: 2.0.4 - experimental
- Returns:
- the new
Completable
instance - Since:
- 2.1
-
compose
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable compose(@NonNull @NonNull CompletableTransformer transformer)
Calls the given transformer function with this instance and returns the function's resultingCompletableSource
wrapped withwrap(CompletableSource)
.- Scheduler:
compose
does not operate by default on a particularScheduler
.
- Parameters:
transformer
- the transformer function, notnull
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- iftransformer
isnull
-
concatWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable concatWith(@NonNull @NonNull CompletableSource other)
Concatenates thisCompletable
with anotherCompletableSource
. An error event from thisCompletable
will be propagated to the downstream observer and will result in skipping the subscription to the nextCompletableSource
.- Scheduler:
concatWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherCompletableSource
, notnull
- Returns:
- the new
Completable
which subscribes to this and then the otherCompletableSource
- Throws:
java.lang.NullPointerException
- ifother
isnull
- See Also:
andThen(CompletableSource)
,andThen(MaybeSource)
,andThen(ObservableSource)
,andThen(SingleSource)
,andThen(Publisher)
-
delay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Completable delay(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Returns aCompletable
which delays the emission of the completion event by the given time.- Scheduler:
delay
does operate by default on thecomputation
Scheduler
.
- Parameters:
time
- the delay timeunit
- the delay unit- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
-
delay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Completable delay(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Returns aCompletable
which delays the emission of the completion event by the given time while running on the specifiedScheduler
.- Scheduler:
delay
operates on theScheduler
you specify.
- Parameters:
time
- the delay timeunit
- the delay unitscheduler
- theScheduler
to run the delayed completion on- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
-
delay
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Completable delay(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean delayError)
Returns aCompletable
which delays the emission of the completion event, and optionally the error as well, by the given time while running on the specifiedScheduler
.- Scheduler:
delay
operates on theScheduler
you specify.
- Parameters:
time
- the delay timeunit
- the delay unitscheduler
- theScheduler
to run the delayed completion ondelayError
- delay the error emission as well?- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
-
delaySubscription
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Completable delaySubscription(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Returns aCompletable
that delays the subscription to the upstream by a given amount of time.- Scheduler:
- This version of
delaySubscription
operates by default on thecomputation
Scheduler
.
History: 2.2.3 - experimental
- Parameters:
time
- the time to delay the subscriptionunit
- the time unit ofdelay
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: Delay
-
delaySubscription
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Completable delaySubscription(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Returns aCompletable
that delays the subscription to the upstream by a given amount of time, both waiting and subscribing on a givenScheduler
.- Scheduler:
- You specify which
Scheduler
this operator will use.
History: 2.2.3 - experimental
- Parameters:
time
- the time to delay the subscriptionunit
- the time unit ofdelay
scheduler
- theScheduler
on which the waiting and subscription will happen- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: Delay
-
doOnComplete
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable doOnComplete(@NonNull @NonNull Action onComplete)
Returns aCompletable
which calls the givenonComplete
Action
if thisCompletable
completes.- Scheduler:
doOnComplete
does not operate by default on a particularScheduler
.
- Parameters:
onComplete
- theAction
to call when this emits anonComplete
event- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifonComplete
isnull
- See Also:
doFinally(Action)
-
doOnDispose
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable doOnDispose(@NonNull @NonNull Action onDispose)
Calls the sharedAction
if aCompletableObserver
subscribed to the currentCompletable
disposes the commonDisposable
it received viaonSubscribe
.- Scheduler:
doOnDispose
does not operate by default on a particularScheduler
.
- Parameters:
onDispose
- theAction
to call when the downstream observer disposes the subscription- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifonDispose
isnull
-
doOnError
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable doOnError(@NonNull @NonNull Consumer<? super java.lang.Throwable> onError)
Returns aCompletable
which calls the givenonError
Consumer
if thisCompletable
emits an error.- Scheduler:
doOnError
does not operate by default on a particularScheduler
.
- Parameters:
onError
- the errorConsumer
receiving the upstreamThrowable
if the upstream signals it viaonError
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifonError
isnull
- See Also:
doFinally(Action)
-
doOnEvent
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable doOnEvent(@NonNull @NonNull Consumer<? super java.lang.Throwable> onEvent)
Returns aCompletable
which calls the givenonEvent
Consumer
with theThrowable
for anonError
ornull
for anonComplete
signal from thisCompletable
before delivering the signal to the downstream.- Scheduler:
doOnEvent
does not operate by default on a particularScheduler
.
- Parameters:
onEvent
- the eventConsumer
that receivesnull
for upstream completion or aThrowable
if the upstream signaled an error- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifonEvent
isnull
-
doOnLifecycle
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable doOnLifecycle(@NonNull @NonNull Consumer<? super Disposable> onSubscribe, @NonNull @NonNull Action onDispose)
Calls the appropriateonXXX
method (shared between allCompletableObserver
s) for the lifecycle events of the sequence (subscription, disposal).- Scheduler:
doOnLifecycle
does not operate by default on a particularScheduler
.
- Parameters:
onSubscribe
- aConsumer
called with theDisposable
sent viaCompletableObserver.onSubscribe(Disposable)
onDispose
- called when the downstream disposes theDisposable
viadispose()
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifonSubscribe
oronDispose
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: Do
-
doOnLifecycle
@CheckReturnValue @NonNull @SchedulerSupport("none") private @NonNull Completable doOnLifecycle(Consumer<? super Disposable> onSubscribe, Consumer<? super java.lang.Throwable> onError, Action onComplete, Action onTerminate, Action onAfterTerminate, Action onDispose)
Returns aCompletable
instance that calls the various callbacks upon the specific lifecycle events.- Scheduler:
doOnLifecycle
does not operate by default on a particularScheduler
.
- Parameters:
onSubscribe
- theConsumer
called when aCompletableObserver
subscribes.onError
- theConsumer
called when this emits anonError
eventonComplete
- theAction
called just before when the currentCompletable
completes normallyonTerminate
- theAction
called just before thisCompletable
terminatesonAfterTerminate
- theAction
called after thisCompletable
completes normallyonDispose
- theAction
called when the downstream disposes the subscription- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifonSubscribe
,onError
,onComplete
onTerminate
,onAfterTerminate
oronDispose
isnull
-
doOnSubscribe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable doOnSubscribe(@NonNull @NonNull Consumer<? super Disposable> onSubscribe)
Returns aCompletable
instance that calls the givenonSubscribe
callback with the disposable that the downstreamCompletableObserver
s receive upon subscription.- Scheduler:
doOnSubscribe
does not operate by default on a particularScheduler
.
- Parameters:
onSubscribe
- theConsumer
called when a downstreamCompletableObserver
subscribes- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifonSubscribe
isnull
-
doOnTerminate
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable doOnTerminate(@NonNull @NonNull Action onTerminate)
Returns aCompletable
instance that calls the givenonTerminate
Action
just before thisCompletable
completes normally or with an exception.- Scheduler:
doOnTerminate
does not operate by default on a particularScheduler
.
- Parameters:
onTerminate
- theAction
to call just before thisCompletable
terminates- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifonTerminate
isnull
- See Also:
doFinally(Action)
-
doAfterTerminate
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable doAfterTerminate(@NonNull @NonNull Action onAfterTerminate)
Returns aCompletable
instance that calls the givenonAfterTerminate
Action
after thisCompletable
completes normally or with an exception.- Scheduler:
doAfterTerminate
does not operate by default on a particularScheduler
.
- Parameters:
onAfterTerminate
- theAction
to call after thisCompletable
terminates- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifonAfterTerminate
isnull
- See Also:
doFinally(Action)
-
doFinally
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable doFinally(@NonNull @NonNull Action onFinally)
Calls the specifiedAction
after thisCompletable
signalsonError
oronComplete
or gets disposed by the downstream.In case of a race between a terminal event and a dispose call, the provided
onFinally
action is executed once per subscription.Note that the
onFinally
action is shared between subscriptions and as such should be thread-safe.- Scheduler:
doFinally
does not operate by default on a particularScheduler
.
History: 2.0.1 - experimental
- Parameters:
onFinally
- theAction
called when thisCompletable
terminates or gets disposed- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifonFinally
isnull
- Since:
- 2.1
-
lift
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable lift(@NonNull @NonNull CompletableOperator onLift)
This method requires advanced knowledge about building operators, please consider other standard composition methods first; Returns aCompletable
which, when subscribed to, invokes theapply(CompletableObserver)
method of the providedCompletableOperator
for each individual downstreamCompletable
and allows the insertion of a custom operator by accessing the downstream'sCompletableObserver
during this subscription phase and providing a newCompletableObserver
, containing the custom operator's intended business logic, that will be used in the subscription process going further upstream.Generally, such a new
CompletableObserver
will wrap the downstream'sCompletableObserver
and forwards theonError
andonComplete
events from the upstream directly or according to the emission pattern the custom operator's business logic requires. In addition, such operator can intercept the flow control calls ofdispose
andisDisposed
that would have traveled upstream and perform additional actions depending on the same business logic requirements.Example:
// Step 1: Create the consumer type that will be returned by the CompletableOperator.apply(): public final class CustomCompletableObserver implements CompletableObserver, Disposable { // The downstream's CompletableObserver that will receive the onXXX events final CompletableObserver downstream; // The connection to the upstream source that will call this class' onXXX methods Disposable upstream; // The constructor takes the downstream subscriber and usually any other parameters public CustomCompletableObserver(CompletableObserver downstream) { this.downstream = downstream; } // In the subscription phase, the upstream sends a Disposable to this class // and subsequently this class has to send a Disposable to the downstream. // Note that relaying the upstream's Disposable directly is not allowed in RxJava @Override public void onSubscribe(Disposable d) { if (upstream != null) { d.dispose(); } else { upstream = d; downstream.onSubscribe(this); } } // Some operators may handle the upstream's error while others // could just forward it to the downstream. @Override public void onError(Throwable throwable) { downstream.onError(throwable); } // When the upstream completes, usually the downstream should complete as well. // In completable, this could also mean doing some side-effects @Override public void onComplete() { System.out.println("Sequence completed"); downstream.onComplete(); } // Some operators may use their own resources which should be cleaned up if // the downstream disposes the flow before it completed. Operators without // resources can simply forward the dispose to the upstream. // In some cases, a disposed flag may be set by this method so that other parts // of this class may detect the dispose and stop sending events // to the downstream. @Override public void dispose() { upstream.dispose(); } // Some operators may simply forward the call to the upstream while others // can return the disposed flag set in dispose(). @Override public boolean isDisposed() { return upstream.isDisposed(); } } // Step 2: Create a class that implements the CompletableOperator interface and // returns the custom consumer type from above in its apply() method. // Such class may define additional parameters to be submitted to // the custom consumer type. final class CustomCompletableOperator implements CompletableOperator { @Override public CompletableObserver apply(CompletableObserver upstream) { return new CustomCompletableObserver(upstream); } } // Step 3: Apply the custom operator via lift() in a flow by creating an instance of it // or reusing an existing one. Completable.complete() .lift(new CustomCompletableOperator()) .test() .assertResult();
Creating custom operators can be complicated and it is recommended one consults the RxJava wiki: Writing operators page about the tools, requirements, rules, considerations and pitfalls of implementing them.
Note that implementing custom operators via this
lift()
method adds slightly more overhead by requiring an additional allocation and indirection per assembled flows. Instead, extending the abstractCompletable
class and creating aCompletableTransformer
with it is recommended.Note also that it is not possible to stop the subscription phase in
lift()
as theapply()
method requires a non-null
CompletableObserver
instance to be returned, which is then unconditionally subscribed to the currentCompletable
. For example, if the operator decided there is no reason to subscribe to the upstream source because of some optimization possibility or a failure to prepare the operator, it still has to return aCompletableObserver
that should immediately dispose the upstream'sDisposable
in itsonSubscribe
method. Again, using aCompletableTransformer
and extending theCompletable
is a better option assubscribeActual(io.reactivex.rxjava3.core.CompletableObserver)
can decide to not subscribe to its upstream after all.- Scheduler:
lift
does not operate by default on a particularScheduler
, however, theCompletableOperator
may use aScheduler
to support its own asynchronous behavior.
- Parameters:
onLift
- theCompletableOperator
that receives the downstream'sCompletableObserver
and should return aCompletableObserver
with custom behavior to be used as the consumer for the currentCompletable
.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifonLift
isnull
- See Also:
- RxJava wiki: Writing operators,
compose(CompletableTransformer)
-
materialize
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull T> @NonNull Single<Notification<T>> materialize()
Maps the signal types of thisCompletable
into aNotification
of the same kind and emits it as a single success value to downstream.- Scheduler:
materialize
does not operate by default on a particularScheduler
.
History: 2.2.4 - experimental
- Type Parameters:
T
- the intended target element type of theNotification
- Returns:
- the new
Single
instance - Since:
- 3.0.0
- See Also:
Single.dematerialize(Function)
-
mergeWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable mergeWith(@NonNull @NonNull CompletableSource other)
Returns aCompletable
which subscribes to this and the otherCompletableSource
and completes when both of them complete or one emits an error.- Scheduler:
mergeWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherCompletableSource
instance- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
-
observeOn
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Completable observeOn(@NonNull @NonNull Scheduler scheduler)
Returns aCompletable
which emits the terminal events from the thread of the specifiedScheduler
.- Scheduler:
observeOn
operates on aScheduler
you specify.
- Parameters:
scheduler
- theScheduler
to emit terminal events on- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifscheduler
isnull
-
onErrorComplete
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable onErrorComplete()
Returns aCompletable
instance that if thisCompletable
emits an error, it will emit anonComplete
and swallow the upstreamThrowable
.- Scheduler:
onErrorComplete
does not operate by default on a particularScheduler
.
- Returns:
- the new
Completable
instance
-
onErrorComplete
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable onErrorComplete(@NonNull @NonNull Predicate<? super java.lang.Throwable> predicate)
Returns aCompletable
instance that if thisCompletable
emits an error and thePredicate
returnstrue
, it will emit anonComplete
and swallow theThrowable
.- Scheduler:
onErrorComplete
does not operate by default on a particularScheduler
.
- Parameters:
predicate
- thePredicate
to call when aThrowable
is emitted which should returntrue
if theThrowable
should be swallowed and replaced with anonComplete
.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifpredicate
isnull
-
onErrorResumeNext
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable onErrorResumeNext(@NonNull @NonNull Function<? super java.lang.Throwable,? extends CompletableSource> fallbackSupplier)
Returns aCompletable
instance that when encounters an error from thisCompletable
, calls the specifiedmapper
Function
that returns aCompletableSource
instance for it and resumes the execution with it.- Scheduler:
onErrorResumeNext
does not operate by default on a particularScheduler
.
- Parameters:
fallbackSupplier
- themapper
Function
that takes the error and should return aCompletableSource
as continuation.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- iffallbackSupplier
isnull
-
onErrorResumeWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable onErrorResumeWith(@NonNull @NonNull CompletableSource fallback)
Resumes the flow with the givenCompletableSource
when the currentCompletable
fails instead of signaling the error viaonError
.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorResumeWith
does not operate by default on a particularScheduler
.
- Parameters:
fallback
- the nextCompletableSource
that will take over if the currentCompletable
encounters an error- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- iffallback
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: Catch
-
onErrorReturn
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull T> @NonNull Maybe<T> onErrorReturn(@NonNull @NonNull Function<? super java.lang.Throwable,? extends @NonNull T> itemSupplier)
Ends the flow with a success item returned by a function for theThrowable
error signaled by the currentCompletable
instead of signaling the error viaonError
.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorReturn
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the item type to return on error- Parameters:
itemSupplier
- a function that returns a single value that will be emitted as success value the currentCompletable
signals anonError
event- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifitemSupplier
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: Catch
-
onErrorReturnItem
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull T> @NonNull Maybe<T> onErrorReturnItem(@NonNull @NonNull T item)
Ends the flow with the given success item when the currentCompletable
fails instead of signaling the error viaonError
.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorReturnItem
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the item type to return on error- Parameters:
item
- the value that is emitted asonSuccess
in case the currentCompletable
signals anonError
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifitem
isnull
- See Also:
- ReactiveX operators documentation: Catch
-
onTerminateDetach
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable onTerminateDetach()
Nulls out references to the upstream producer and downstreamCompletableObserver
if the sequence is terminated or downstream callsdispose()
.- Scheduler:
onTerminateDetach
does not operate by default on a particularScheduler
.
History: 2.1.5 - experimental
- Returns:
- the new
Completable
instance - Since:
- 2.2
-
repeat
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable repeat()
Returns aCompletable
that repeatedly subscribes to thisCompletable
until disposed.- Scheduler:
repeat
does not operate by default on a particularScheduler
.
- Returns:
- the new
Completable
instance
-
repeat
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable repeat(long times)
Returns aCompletable
that subscribes repeatedly at most the given number of times to thisCompletable
.- Scheduler:
repeat
does not operate by default on a particularScheduler
.
- Parameters:
times
- the number of times the re-subscription should happen- Returns:
- the new
Completable
instance - Throws:
java.lang.IllegalArgumentException
- iftimes
is negative
-
repeatUntil
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable repeatUntil(@NonNull @NonNull BooleanSupplier stop)
Returns aCompletable
that repeatedly subscribes to thisCompletable
so long as the given stopBooleanSupplier
returnsfalse
.- Scheduler:
repeatUntil
does not operate by default on a particularScheduler
.
- Parameters:
stop
- theBooleanSupplier
that should returntrue
to stop resubscribing.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifstop
isnull
-
repeatWhen
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable repeatWhen(@NonNull @NonNull Function<? super Flowable<java.lang.Object>,? extends org.reactivestreams.Publisher<?>> handler)
Returns aCompletable
instance that repeats when thePublisher
returned by the handlerFunction
emits an item or completes when thisPublisher
emits anonComplete
event.- Scheduler:
repeatWhen
does not operate by default on a particularScheduler
.
- Parameters:
handler
- theFunction
that transforms the stream of values indicating the completion of thisCompletable
and returns aPublisher
that emits items for repeating or completes to indicate the repetition should stop- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifhandler
isnull
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable retry()
Returns aCompletable
that retries thisCompletable
as long as it emits anonError
event.- Scheduler:
retry
does not operate by default on a particularScheduler
.
- Returns:
- the new
Completable
instance
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable retry(@NonNull @NonNull BiPredicate<? super java.lang.Integer,? super java.lang.Throwable> predicate)
Returns aCompletable
that retries thisCompletable
in case of an error as long as thepredicate
returnstrue
.- Scheduler:
retry
does not operate by default on a particularScheduler
.
- Parameters:
predicate
- thePredicate
called when thisCompletable
emits an error with the repeat count and the latestThrowable
and should returntrue
to retry.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifpredicate
isnull
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable retry(long times)
Returns aCompletable
that when thisCompletable
emits an error, retries at most the given number of times before giving up and emitting the last error.- Scheduler:
retry
does not operate by default on a particularScheduler
.
- Parameters:
times
- the number of times to resubscribe if the currentCompletable
fails- Returns:
- the new
Completable
instance - Throws:
java.lang.IllegalArgumentException
- iftimes
is negative
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable retry(long times, @NonNull @NonNull Predicate<? super java.lang.Throwable> predicate)
Returns aCompletable
that when thisCompletable
emits an error, retries at most times or until the predicate returnsfalse
, whichever happens first and emitting the last error.- Scheduler:
retry
does not operate by default on a particularScheduler
.
History: 2.1.8 - experimental
- Parameters:
times
- the number of times to resubscribe if the currentCompletable
failspredicate
- thePredicate
that is called with the latestThrowable
and should returntrue
to indicate the returnedCompletable
should resubscribe to thisCompletable
.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifpredicate
isnull
java.lang.IllegalArgumentException
- iftimes
is negative- Since:
- 2.2
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable retry(@NonNull @NonNull Predicate<? super java.lang.Throwable> predicate)
Returns aCompletable
that when thisCompletable
emits an error, calls the given predicate with the latestThrowable
to decide whether to resubscribe to the upstream or not.- Scheduler:
retry
does not operate by default on a particularScheduler
.
- Parameters:
predicate
- thePredicate
that is called with the latestThrowable
and should returntrue
to indicate the returnedCompletable
should resubscribe to thisCompletable
.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifpredicate
isnull
-
retryUntil
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable retryUntil(@NonNull @NonNull BooleanSupplier stop)
Retries until the given stop function returnstrue
.- Scheduler:
retryUntil
does not operate by default on a particularScheduler
.
- Parameters:
stop
- the function that should returntrue
to stop retrying- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifstop
isnull
- Since:
- 3.0.0
-
retryWhen
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable retryWhen(@NonNull @NonNull Function<? super Flowable<java.lang.Throwable>,? extends org.reactivestreams.Publisher<?>> handler)
Returns aCompletable
which given aPublisher
and when thisCompletable
emits an error, delivers that error through aFlowable
and thePublisher
should signal a value indicating a retry in response or a terminal event indicating a termination.Note that the inner
Publisher
returned by the handler function should signal eitheronNext
,onError
oronComplete
in response to the receivedThrowable
to indicate the operator should retry or terminate. If the upstream to the operator is asynchronous, signalingonNext
followed byonComplete
immediately may result in the sequence to be completed immediately. Similarly, if this innerPublisher
signalsonError
oronComplete
while the upstream is active, the sequence is terminated with the same signal immediately.The following example demonstrates how to retry an asynchronous source with a delay:
Completable.timer(1, TimeUnit.SECONDS) .doOnSubscribe(s -> System.out.println("subscribing")) .doOnComplete(() -> { throw new RuntimeException(); }) .retryWhen(errors -> { AtomicInteger counter = new AtomicInteger(); return errors .takeWhile(e -> counter.getAndIncrement() != 3) .flatMap(e -> { System.out.println("delay retry by " + counter.get() + " second(s)"); return Flowable.timer(counter.get(), TimeUnit.SECONDS); }); }) .blockingAwait();
- Scheduler:
retryWhen
does not operate by default on a particularScheduler
.
- Parameters:
handler
- theFunction
that receives aFlowable
deliveringThrowable
s and should return aPublisher
that emits items to indicate retries or emits terminal events to indicate termination.- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifhandler
isnull
-
safeSubscribe
@SchedulerSupport("none") public final void safeSubscribe(@NonNull @NonNull CompletableObserver observer)
Wraps the givenCompletableObserver
, catches anyRuntimeException
s thrown by itsCompletableObserver.onSubscribe(Disposable)
,CompletableObserver.onError(Throwable)
orCompletableObserver.onComplete()
methods and routes those to the global error handler viaRxJavaPlugins.onError(Throwable)
.By default, the
Completable
protocol forbids theonXXX
methods to throw, but someCompletableObserver
implementation may do it anyway, causing undefined behavior in the upstream. This method and the underlying safe wrapper ensures such misbehaving consumers don't disrupt the protocol.- Scheduler:
safeSubscribe
does not operate by default on a particularScheduler
.
- Parameters:
observer
- the potentially misbehavingCompletableObserver
- Throws:
java.lang.NullPointerException
- ifobserver
isnull
- Since:
- 3.0.0
- See Also:
subscribe(Action, Consumer)
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable startWith(@NonNull @NonNull CompletableSource other)
Returns aCompletable
which first runs the otherCompletableSource
then the currentCompletable
if the other completed normally.- Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherCompletableSource
to run first- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public final <@NonNull T> @NonNull Flowable<T> startWith(@NonNull @NonNull SingleSource<@NonNull T> other)
Returns aFlowable
which first runs the otherSingleSource
then the currentCompletable
if the other succeeded normally.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the element type of theother
SingleSource
.- Parameters:
other
- the otherSingleSource
to run first- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public final <@NonNull T> @NonNull Flowable<T> startWith(@NonNull @NonNull MaybeSource<@NonNull T> other)
Returns aFlowable
which first runs the otherMaybeSource
then the currentCompletable
if the other succeeded or completed normally.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the element type of theother
MaybeSource
.- Parameters:
other
- the otherMaybeSource
to run first- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull T> @NonNull Observable<T> startWith(@NonNull @NonNull ObservableSource<@NonNull T> other)
Returns anObservable
which first delivers the events of the otherObservableSource
then runs the currentCompletable
.- Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
other
- the otherObservableSource
to run first- Returns:
- the new
Observable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
-
startWith
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public final <@NonNull T> @NonNull Flowable<T> startWith(@NonNull @NonNull org.reactivestreams.Publisher<@NonNull T> other)
Returns aFlowable
which first delivers the events of the otherPublisher
then runs the currentCompletable
.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well. - Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
other
- the otherPublisher
to run first- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
-
hide
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable hide()
Hides the identity of thisCompletable
and itsDisposable
.Allows preventing certain identity-based optimizations (fusion).
- Scheduler:
hide
does not operate by default on a particularScheduler
.
History: 2.0.5 - experimental
- Returns:
- the new
Completable
instance - Since:
- 2.1
-
subscribe
@SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe()
Subscribes to thisCompletable
and returns aDisposable
which can be used to dispose the subscription.- Scheduler:
subscribe
does not operate by default on a particularScheduler
.
- Returns:
- the new
Disposable
that can be used for disposing the subscription at any time - See Also:
subscribe(Action, Consumer, DisposableContainer)
-
subscribe
@SchedulerSupport("none") public final void subscribe(@NonNull @NonNull CompletableObserver observer)
Description copied from interface:CompletableSource
Subscribes the givenCompletableObserver
to thisCompletableSource
instance.- Specified by:
subscribe
in interfaceCompletableSource
- Parameters:
observer
- theCompletableObserver
, notnull
-
subscribeActual
protected abstract void subscribeActual(@NonNull @NonNull CompletableObserver observer)
Implement this method to handle the incomingCompletableObserver
s and perform the business logic in your operator.There is no need to call any of the plugin hooks on the current
Completable
instance or theCompletableObserver
; all hooks and basic safeguards have been applied bysubscribe(CompletableObserver)
before this method gets called.- Parameters:
observer
- theCompletableObserver
instance, nevernull
-
subscribeWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull E extends CompletableObserver> E subscribeWith(@NonNull E observer)
Subscribes a givenCompletableObserver
(subclass) to thisCompletable
and returns the givenCompletableObserver
as is.Usage example:
Completable source = Completable.complete().delay(1, TimeUnit.SECONDS); CompositeDisposable composite = new CompositeDisposable(); DisposableCompletableObserver ds = new DisposableCompletableObserver() { // ... }; composite.add(source.subscribeWith(ds));
- Scheduler:
subscribeWith
does not operate by default on a particularScheduler
.
- Type Parameters:
E
- the type of theCompletableObserver
to use and return- Parameters:
observer
- theCompletableObserver
(subclass) to use and return, notnull
- Returns:
- the input
observer
- Throws:
java.lang.NullPointerException
- ifobserver
isnull
- Since:
- 2.0
-
subscribe
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Disposable subscribe(@NonNull @NonNull Action onComplete, @NonNull @NonNull Consumer<? super java.lang.Throwable> onError)
Subscribes to thisCompletable
and calls back either theonError
oronComplete
functions.- Scheduler:
subscribe
does not operate by default on a particularScheduler
.
- Parameters:
onComplete
- theAction
that is called if theCompletable
completes normallyonError
- theConsumer
that is called if thisCompletable
emits an error- Returns:
- the new
Disposable
that can be used for disposing the subscription at any time - Throws:
java.lang.NullPointerException
- ifonComplete
oronError
isnull
- See Also:
subscribe(Action, Consumer, DisposableContainer)
-
subscribe
@SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Action onComplete, @NonNull @NonNull Consumer<? super java.lang.Throwable> onError, @NonNull @NonNull DisposableContainer container)
Wraps the given onXXX callbacks into aDisposable
CompletableObserver
, adds it to the givenDisposableContainer
and ensures, that if the upstream terminates or this particularDisposable
is disposed, theCompletableObserver
is removed from the given composite.The
CompletableObserver
will be removed after the callback for the terminal event has been invoked.- Scheduler:
subscribe
does not operate by default on a particularScheduler
.
- Parameters:
onError
- the callback for an upstream erroronComplete
- the callback for an upstream completioncontainer
- theDisposableContainer
(such asCompositeDisposable
) to add and remove the createdDisposable
CompletableObserver
- Returns:
- the
Disposable
that allows disposing the particular subscription. - Throws:
java.lang.NullPointerException
- ifonComplete
,onError
orcontainer
isnull
- Since:
- 3.1.0
-
subscribe
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Disposable subscribe(@NonNull @NonNull Action onComplete)
Subscribes to thisCompletable
and calls the givenAction
when thisCompletable
completes normally.If the
Completable
emits an error, it is wrapped into anOnErrorNotImplementedException
and routed to the globalRxJavaPlugins.onError(Throwable)
handler.- Scheduler:
subscribe
does not operate by default on a particularScheduler
.
- Parameters:
onComplete
- theAction
called when thisCompletable
completes normally- Returns:
- the new
Disposable
that can be used for disposing the subscription at any time - Throws:
java.lang.NullPointerException
- ifonComplete
isnull
- See Also:
subscribe(Action, Consumer, DisposableContainer)
-
subscribeOn
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Completable subscribeOn(@NonNull @NonNull Scheduler scheduler)
Returns aCompletable
which subscribes the downstream subscriber on the specified scheduler, making sure the subscription side-effects happen on that specific thread of theScheduler
.- Scheduler:
subscribeOn
operates on aScheduler
you specify.
- Parameters:
scheduler
- theScheduler
to subscribe on- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifscheduler
isnull
-
takeUntil
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable takeUntil(@NonNull @NonNull CompletableSource other)
Terminates the downstream if this or the otherCompletable
terminates (wins the termination race) while disposing the connection to the losing source.- Scheduler:
takeUntil
does not operate by default on a particularScheduler
.- Error handling:
- If both this and the other sources signal an error, only one of the errors
is signaled to the downstream and the other error is signaled to the global
error handler via
RxJavaPlugins.onError(Throwable)
.
History: 2.1.17 - experimental
- Parameters:
other
- the other completable source to observe for the terminal signals- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 2.2
-
timeout
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Completable timeout(long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Returns aCompletabl
e that runs thisCompletable
and emits aTimeoutException
in case thisCompletable
doesn't complete within the given time.- Scheduler:
timeout
signals theTimeoutException
on thecomputation
Scheduler
.
- Parameters:
timeout
- the timeout valueunit
- the unit oftimeout
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
-
timeout
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Completable timeout(long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull CompletableSource fallback)
Returns aCompletable
that runs thisCompletable
and switches to the otherCompletableSource
in case thisCompletable
doesn't complete within the given time.- Scheduler:
timeout
subscribes to the otherCompletableSource
on thecomputation
Scheduler
.
- Parameters:
timeout
- the timeout valueunit
- the unit oftimeout
fallback
- the otherCompletableSource
instance to switch to in case of a timeout- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifunit
orfallback
isnull
-
timeout
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Completable timeout(long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Returns aCompletable
that runs thisCompletable
and emits aTimeoutException
in case thisCompletable
doesn't complete within the given time while "waiting" on the specifiedScheduler
.- Scheduler:
timeout
signals theTimeoutException
on theScheduler
you specify.
- Parameters:
timeout
- the timeout valueunit
- the unit oftimeout
scheduler
- theScheduler
to use to wait for completion and signalTimeoutException
- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
-
timeout
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Completable timeout(long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler, @NonNull @NonNull CompletableSource fallback)
Returns aCompletable
that runs thisCompletable
and switches to the otherCompletableSource
in case thisCompletable
doesn't complete within the given time while "waiting" on the specifiedScheduler
.- Scheduler:
timeout
subscribes to the otherCompletableSource
on theScheduler
you specify.
- Parameters:
timeout
- the timeout valueunit
- the unit oftimeout
scheduler
- theScheduler
to use to wait for completionfallback
- the otherCompletable
instance to switch to in case of a timeout- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifunit
,scheduler
orfallback
isnull
-
timeout0
@CheckReturnValue @NonNull @SchedulerSupport("custom") private @NonNull Completable timeout0(long timeout, java.util.concurrent.TimeUnit unit, Scheduler scheduler, CompletableSource fallback)
Returns aCompletable
that runs thisCompletable
and optionally switches to the otherCompletableSource
in case thisCompletable
doesn't complete within the given time while "waiting" on the specifiedScheduler
.- Scheduler:
- You specify the
Scheduler
this operator runs on.
- Parameters:
timeout
- the timeout valueunit
- the unit oftimeout
scheduler
- theScheduler
to use to wait for completionfallback
- the otherCompletable
instance to switch to in case of a timeout, ifnull
aTimeoutException
is emitted instead- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifunit
,scheduler
orfallback
isnull
-
to
@CheckReturnValue @SchedulerSupport("none") public final <R> R to(@NonNull @NonNull CompletableConverter<? extends R> converter)
Calls the specifiedCompletableConverter
function during assembly time and returns its resulting value.This allows fluent conversion to any other type.
- Scheduler:
to
does not operate by default on a particularScheduler
.
History: 2.1.7 - experimental
- Type Parameters:
R
- the resulting object type- Parameters:
converter
- theCompletableConverter
that receives the currentCompletable
instance and returns a value to be the result ofto()
- Returns:
- the converted value
- Throws:
java.lang.NullPointerException
- ifconverter
isnull
- Since:
- 2.2
-
toFlowable
@CheckReturnValue @BackpressureSupport(FULL) @SchedulerSupport("none") @NonNull public final <@NonNull T> @NonNull Flowable<T> toFlowable()
Returns aFlowable
which when subscribed to subscribes to thisCompletable
and relays the terminal events to the downstreamSubscriber
.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
toFlowable
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Returns:
- the new
Flowable
instance
-
toFuture
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull java.util.concurrent.Future<java.lang.Void> toFuture()
Returns aFuture
representing the termination of the currentCompletable
via anull
value.Cancelling the
Future
will cancel the subscription to the currentCompletable
.- Scheduler:
toFuture
does not operate by default on a particularScheduler
.
- Returns:
- the new
Future
instance - Since:
- 3.0.0
- See Also:
- ReactiveX documentation: To
-
toMaybe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull T> @NonNull Maybe<T> toMaybe()
Converts thisCompletable
into aMaybe
.- Scheduler:
toMaybe
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Returns:
- the new
Maybe
instance
-
toObservable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull T> @NonNull Observable<T> toObservable()
Returns anObservable
which when subscribed to subscribes to thisCompletable
and relays the terminal events to the downstreamObserver
.- Scheduler:
toObservable
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Returns:
- the new
Observable
created
-
toSingle
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull T> @NonNull Single<T> toSingle(@NonNull @NonNull Supplier<? extends @NonNull T> completionValueSupplier)
Converts thisCompletable
into aSingle
which when thisCompletable
completes normally, calls the givenSupplier
and emits its returned value throughonSuccess
.- Scheduler:
toSingle
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
completionValueSupplier
- the value supplier called when thisCompletable
completes normally- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifcompletionValueSupplier
isnull
-
toSingleDefault
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull T> @NonNull Single<T> toSingleDefault(@NonNull T completionValue)
Converts thisCompletable
into aSingle
which when thisCompletable
completes normally, emits the given value throughonSuccess
.- Scheduler:
toSingleDefault
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
completionValue
- the value to emit when thisCompletable
completes normally- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifcompletionValue
isnull
-
unsubscribeOn
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Completable unsubscribeOn(@NonNull @NonNull Scheduler scheduler)
Returns aCompletable
which makes sure when an observer disposes the subscription, thedispose()
method is called on the specifiedScheduler
.- Scheduler:
unsubscribeOn
callsdispose()
of the upstream on theScheduler
you specify.
- Parameters:
scheduler
- the targetScheduler
where to execute the disposing- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifscheduler
isnull
-
test
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull TestObserver<java.lang.Void> test()
Creates aTestObserver
and subscribes it to thisCompletable
.- Scheduler:
test
does not operate by default on a particularScheduler
.
- Returns:
- the new
TestObserver
instance - Since:
- 2.0
-
test
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull TestObserver<java.lang.Void> test(boolean dispose)
Creates aTestObserver
optionally in cancelled state, then subscribes it to thisCompletable
.- Parameters:
dispose
- iftrue
, theTestObserver
will be cancelled before subscribing to thisCompletable
.- Scheduler:
test
does not operate by default on a particularScheduler
.
- Returns:
- the new
TestObserver
instance - Since:
- 2.0
-
fromCompletionStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public static @NonNull Completable fromCompletionStage(@NonNull @NonNull java.util.concurrent.CompletionStage<?> stage)
Signals completion (or error) when theCompletionStage
terminates.Note that the operator takes an already instantiated, running or terminated
CompletionStage
. If theCompletionStage
is to be created per consumer upon subscription, usedefer(Supplier)
aroundfromCompletionStage
:Maybe.defer(() -> Completable.fromCompletionStage(createCompletionStage()));
Canceling the flow can't cancel the execution of the
CompletionStage
becauseCompletionStage
itself doesn't support cancellation. Instead, the operator detaches from theCompletionStage
.- Scheduler:
fromCompletionStage
does not operate by default on a particularScheduler
.
- Parameters:
stage
- theCompletionStage
to convert to aCompletable
and signalonComplete
oronError
when theCompletionStage
terminates normally or with a failure- Returns:
- the new
Completable
instance - Throws:
java.lang.NullPointerException
- ifstage
isnull
- Since:
- 3.0.0
-
toCompletionStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@Nullable T> @NonNull java.util.concurrent.CompletionStage<T> toCompletionStage(@Nullable T defaultItem)
Signals the given default item when the upstream completes or signals the upstream error via aCompletionStage
.The upstream can be canceled by converting the resulting
CompletionStage
intoCompletableFuture
viaCompletionStage.toCompletableFuture()
and callingCompletableFuture.cancel(boolean)
on it. The upstream will be also cancelled if the resultingCompletionStage
is converted to and completed manually byCompletableFuture.complete(Object)
orCompletableFuture.completeExceptionally(Throwable)
.CompletionStage
s don't have a notion of emptiness and allownull
s, therefore, one can either use adefaultItem
ofnull
or turn the flow into a sequence ofOptional
s and default toOptional.empty()
:CompletionStage<Optional<T>> stage = source.map(Optional::of).toCompletionStage(Optional.empty());
- Scheduler:
toCompletionStage
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of the default item to signal upon completion- Parameters:
defaultItem
- the item to signal upon completion- Returns:
- the new
CompletionStage
instance - Since:
- 3.0.0
-
-