Completable class represents a deferred computation without any value but
only indication for completion or exception.
Completable behaves similarly to Observable except that it can only emit either
a completion or error signal (there is no onNext or onSuccess as with the other
reactive types).
The Completable class implements the CompletableSource base interface and the default consumer
type it interacts with is the CompletableObserver via the subscribe(CompletableObserver) method.
The Completable operates with the following sequential protocol:
onSubscribe (onError | onComplete)?
Note that as with the Observable protocol, onError and onComplete are mutually exclusive events.
Like Observable, a running Completable can be stopped through the Disposable instance
provided to consumers through CompletableObserver#onSubscribe.
Like an Observable, a Completable 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 or Observable 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 the
void return of the subscribe(CompletableObserver) method) and it is the
responsibility of the implementor of the CompletableObserver to allow this to happen.
RxJava supports such usage with the standard
DisposableCompletableObserver instance.
For convenience, the subscribeWith(CompletableObserver) method is provided as well to
allow working with a CompletableObserver (or subclass) instance to be applied with in
a fluent manner (such as in the example above).
io.reactivex.rxjava3.observers.DisposableCompletableObserver
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static @NonNull Completable | Returns: the newCompletable instancethe sources)Iterable of source Completables. A subscription to each source will
occur in the same order as in this Iterable.Returns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe array of source sources)Completables. A subscription to each source will
occur in the same order as in this array.Returns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe other other)CompletableSource, not null. A subscription to this provided source will occur after subscribing
to the current source.Returns a |
| public final < the value type of the next T> @NonNull ObservableObservableSource | Returns: the newObservable that composes this Completable and the next ObservableSourcethe next)ObservableSource to subscribe after this Completable is completed, not nullReturns an |
| public final < the value type of the next T> @NonNull FlowablePublisher | Returns: the newFlowable that composes this Completable and the next Publisherthe next)Publisher to subscribe after this Completable is completed, not nullReturns a |
| public final < the value type of the next T> @NonNull SingleSingleSource | Returns: the newSingle that composes this Completable and the next SingleSourcethe next)SingleSource to subscribe after this Completable is completed, not nullReturns a |
| public final < the value type of the next T> @NonNull MaybeMaybeSource | Returns: the newMaybe that composes this Completable and the next MaybeSourcethe next)MaybeSource to subscribe after this Completable is completed, not nullReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe other next)CompletableSource, not nullReturns a |
| public final void | blockingAwait()
Subscribes to and awaits the termination of this |
| public final boolean | Returns: true if the this Completable instance completed normally within the time limit,
false if the timeout elapsed before this Completable terminated.the timeout value timeout, @NonNull TimeUnit the timeout unit unit)Subscribes to and awaits the termination of this |
| public final void | blockingSubscribe()
Subscribes to the current |
| public final void | blockingSubscribe(@NonNull Action
the onComplete)Action to call if the current Completable completes normallySubscribes to the current |
| public final void | blockingSubscribe(@NonNull Action
the onComplete, @NonNull Consumer<? super Throwable> Action to call if the current Completable completes normallythe onError)Consumer to call if the current Completable signals an errorSubscribes to the current |
| public final void | blockingSubscribe(@NonNull CompletableObserver
the observer)CompletableObserver to call methods on the current threadSubscribes to the current |
| public final @NonNull Completable | Returns: the newCompletable instanceSubscribes to this |
| public static @NonNull Completable | Returns: the sharedCompletable instanceReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe transformer function, not transformer)nullCalls the given transformer function with this instance and returns the function's resulting
|
| public static @NonNull Completable | Returns: the newCompletable instancethe sources to concatenate sources)Returns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe sources to concatenate sources)Returns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe sources to concatenate sources, int the number of sources to prefetch from the sources prefetch)Returns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe sources to concatenate sources)Returns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe sources to concatenate sources)Returns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe sources to concatenate sources)Returns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe sources to concatenate sources)Returns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe sources to concatenate sources, int the number of sources to prefetch from the sources prefetch)Returns a |
| public final @NonNull Completable | Returns: the newCompletable which subscribes to this and then the other CompletableSourcethe other other)CompletableSource, not nullConcatenates this |
| public static @NonNull Completable | Returns: the newCompletable instancethe emitter that is called when a source)CompletableObserver subscribes to the returned CompletableProvides an API (via a cold |
| public static @NonNull Completable | Returns: the newCompletable instancethe supplier that returns the supplier)Completable that will be subscribed to.Defers the subscription to a |
| public final @NonNull Completable | |
| public final @NonNull Completable | Returns: the newCompletable instancethe delay time time, @NonNull TimeUnit the delay unit unit, @NonNull Scheduler the scheduler)Scheduler to run the delayed completion onReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe delay time time, @NonNull TimeUnit the delay unit unit, @NonNull Scheduler the scheduler, boolean Scheduler to run the delayed completion ondelay the error emission as well? delayError)Returns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe time to delay the subscription time, @NonNull TimeUnit the time unit of unit)delayReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe time to delay the subscription time, @NonNull TimeUnit the time unit of unit, @NonNull Scheduler delaythe scheduler)Scheduler on which the waiting and subscription will happenReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe onAfterTerminate)Action to call after this Completable terminatesReturns a |
| public final @NonNull Completable | |
| public final @NonNull Completable | Returns: the newCompletable instancethe onComplete)Action to call when this emits an onComplete eventReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe onDispose)Action to call when the downstream observer disposes the subscriptionCalls the shared |
| public final @NonNull Completable | |
| public final @NonNull Completable | Returns: the newCompletable instancethe event onEvent)Consumer that receives null for upstream
completion or a Throwable if the upstream signaled an errorReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancecalled when the downstream disposes the onDispose)Disposable via dispose()Calls the appropriate |
| private @NonNull Completable | Returns: the newCompletable instancethe onSubscribe, final Consumer<? super Throwable> Consumer called when a CompletableObserver subscribes.the onError, final Action Consumer called when this emits an onError eventthe onComplete, final Action Action called just before when the current Completable completes normallythe onTerminate, final Action Action called just before this Completable terminatesthe onAfterTerminate, final Action Action called after this Completable completes normallythe onDispose)Action called when the downstream disposes the subscriptionReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe onSubscribe)Consumer called when a downstream CompletableObserver subscribesReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe onTerminate)Action to call just before this Completable terminatesReturns a |
| public static @NonNull Completable | |
| public static @NonNull Completable | |
| public static @NonNull Completable | Returns: the newCompletable instancethe action)Action to run for each subscribing CompletableObserverReturns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe callable)Callable instance to execute for each subscribing CompletableObserverReturns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe stage)CompletionStage to convert to a Completable and
signal onComplete or onError when the CompletionStage terminates normally or with a failureSignals completion (or error) when the |
| public static @NonNull Completable | Returns: the newCompletable instancethe future)Future to react toReturns a |
| public static < the value type of the T> @NonNull CompletableMaybeSource element | Returns: the newCompletable instancethe maybe)MaybeSource instance to subscribe to, not nullReturns a |
| public static < the type of the T> @NonNull CompletableObservableSource | Returns: the newCompletable instancethe observable)ObservableSource instance to subscribe to, not nullReturns a |
| public static < the type of the T> @NonNull CompletablePublisher | Returns: the newCompletable instancethe publisher)Publisher instance to subscribe to, not nullReturns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe run)Runnable to run for each CompletableObserverReturns a |
| public static < the value type of the T> @NonNull CompletableSingleSource | Returns: the newCompletable instancethe single)SingleSource instance to subscribe to, not nullReturns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe supplier)Supplier instance to execute for each CompletableObserverReturns a |
| public final @NonNull Completable | Returns: the newCompletable instanceHides the identity of this |
| public final @NonNull Completable | Returns: the newCompletable instancethe onLift)CompletableOperator that receives the downstream's CompletableObserver and should return
a CompletableObserver with custom behavior to be used as the consumer for the current
Completable.This method requires advanced knowledge about building operators, please consider
other standard composition methods first;
Returns a |
| public final < the intended target element type of the T> @NonNull SingleNotification | Returns: the newSingle instanceMaps the signal types of this |
| public static @NonNull Completable | Returns: the newCompletable instancethe sources)Iterable sequence of CompletableSources.Returns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe sources)Publisher sequence of CompletableSources.Returns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe sources, int Publisher sequence of CompletableSources.the maximum number of concurrent subscriptions maxConcurrency)Returns a |
| private static @NonNull Completable | Returns: the newCompletable instancethe sources, int Publisher sequence of CompletableSources.the maximum number of concurrent subscriptions maxConcurrency, boolean delay all errors from the main source and from the inner delayErrors)CompletableSources?Returns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe array of sources)CompletableSources.Returns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe array of sources)CompletableSourcesReturns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe sequence of sources)CompletableSourcesReturns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe sequence of sources)CompletableSourcesReturns a |
| public static @NonNull Completable | Returns: the newCompletable instancethe sequence of sources, int CompletableSourcesthe maximum number of concurrent subscriptions to have
at a time to the inner maxConcurrency)CompletableSourcesReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe other other)CompletableSource instanceReturns a |
| public static @NonNull Completable | Returns: the singleton instance that never callsonError or onCompleteReturns a |
| public final @NonNull Completable | |
| public final @NonNull Completable | Returns: the newCompletable instanceReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe predicate)Predicate to call when a Throwable is emitted which should return true
if the Throwable should be swallowed and replaced with an onComplete.Returns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe fallbackSupplier)mapper Function that takes the error and should return a CompletableSource as
continuation.Returns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe next fallback)CompletableSource that will take over if the current Completable encounters
an errorResumes the flow with the given |
| public final < the item type to return on error T> @NonNull Maybe | Returns: the newMaybe instancea function that returns a single value that will be emitted as success value
the current itemSupplier)Completable signals an onError eventEnds the flow with a success item returned by a function for the |
| public final < the item type to return on error T> @NonNull Maybe | Returns: the newMaybe instancethe value that is emitted as item)onSuccess in case the current Completable signals an onErrorEnds the flow with the given success item when the current |
| public final @NonNull Completable | Returns: the newCompletable instanceNulls out references to the upstream producer and downstream |
| public final @NonNull Completable | Returns: the newCompletable instanceReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe number of times the re-subscription should happen times)Returns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe stop)BooleanSupplier that should return true to stop resubscribing.Returns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe handler)Function that transforms the stream of values indicating the completion of
this Completable and returns a Publisher that emits items for repeating or completes to indicate the
repetition should stopReturns a |
| public final @NonNull Completable | Returns: the newCompletable instanceReturns a |
| public final @NonNull Completable | Returns: the newCompletable instanceReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe number of times to resubscribe if the current times)Completable failsReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe number of times to resubscribe if the current times, @NonNull Predicate<? super Throwable> predicate)Completable failsReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe predicate)Predicate that is called with the latest Throwable and should return
true to indicate the returned Completable should resubscribe to this Completable.Returns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe function that should return stop)true to stop retryingRetries until the given stop function returns |
| public final @NonNull Completable | Returns: the newCompletable instancethe handler)Function that receives a Flowable delivering Throwables and should return a Publisher that
emits items to indicate retries or emits terminal events to indicate termination.Returns a |
| public final void | safeSubscribe(@NonNull CompletableObserver
the potentially misbehaving observer)CompletableObserverWraps the given |
| public static @NonNull Single | Returns: the newSingle instancethe first source1, @NonNull CompletableSource CompletableSource instancethe second source2)CompletableSource instanceCompares two |
| public final @NonNull Completable | Returns: the newCompletable instancethe other other)CompletableSource to run firstReturns a |
| public final < the element type of the T> @NonNull Flowableother SingleSource. | Returns: the newFlowable instancethe other other)SingleSource to run firstReturns a |
| public final < the element type of the T> @NonNull Flowableother MaybeSource. | Returns: the newFlowable instancethe other other)MaybeSource to run firstReturns a |
| public final < the value type T> @NonNull Observable | Returns: the newObservable instancethe other other)ObservableSource to run firstReturns an |
| public final < the value type T> @NonNull Flowable | |
| public final @NonNull Disposable | Returns: the newDisposable that can be used for disposing the subscription at any timeSubscribes to this |
| public final void | |
| public final @NonNull Disposable | Returns: the newDisposable that can be used for disposing the subscription at any timethe onComplete, @NonNull Consumer<? super Throwable> Action that is called if the Completable completes normallythe onError)Consumer that is called if this Completable emits an errorSubscribes to this |
| public final @NonNull Disposable | Returns: theDisposable that allows disposing the particular subscription.the callback for an upstream completion onComplete, @NonNull Consumer<? super Throwable> the callback for an upstream error onError, @NonNull DisposableContainer the container)DisposableContainer (such as CompositeDisposable) to add and remove the
created Disposable CompletableObserverWraps the given onXXX callbacks into a |
| public final @NonNull Disposable | Returns: the newDisposable that can be used for disposing the subscription at any timethe onComplete)Action called when this Completable completes normallySubscribes to this |
| protected abstract void | subscribeActual(@NonNull CompletableObserver
the observer)CompletableObserver instance, never nullImplement this method to handle the incoming |
| public final @NonNull Completable | Returns: the newCompletable instancethe scheduler)Scheduler to subscribe onReturns a |
| public final < the type of the E extends CompletableObserver> ECompletableObserver to use and return | Returns: the inputobserverthe observer)CompletableObserver (subclass) to use and return, not nullSubscribes a given |
| public static @NonNull Completable | Returns: the newCompletable instancethe sources)Publisher sequence of inner CompletableSources to switch betweenSwitches between |
| public static @NonNull Completable | Returns: the newCompletable instancethe sources)Publisher sequence of inner CompletableSources to switch betweenSwitches between |
| public final @NonNull Completable | Returns: the newCompletable instancethe other completable source to observe for the terminal signals other)Terminates the downstream if this or the other |
| public final @NonNull TestObserver | Returns: the newTestObserver instanceCreates a |
| public final @NonNull TestObserver | Returns: the newTestObserver instanceif dispose)true, the TestObserver will be cancelled before subscribing to this
Completable.
Creates a |
| public final @NonNull Completable | Returns: the newCompletable instancethe timeout value timeout, @NonNull TimeUnit the unit of unit)timeoutReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe timeout value timeout, @NonNull TimeUnit the unit of unit, @NonNull CompletableSource timeoutthe other fallback)CompletableSource instance to switch to in case of a timeoutReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe timeout value timeout, @NonNull TimeUnit the unit of unit, @NonNull Scheduler timeoutthe scheduler)Scheduler to use to wait for completion and signal TimeoutExceptionReturns a |
| public final @NonNull Completable | Returns: the newCompletable instancethe timeout value timeout, @NonNull TimeUnit the unit of unit, @NonNull Scheduler timeoutthe scheduler, @NonNull CompletableSource Scheduler to use to wait for completionthe other fallback)Completable instance to switch to in case of a timeoutReturns a |
| private @NonNull Completable | Returns: the newCompletable instancethe timeout value timeout, TimeUnit the unit of unit, Scheduler timeoutthe scheduler, CompletableSource Scheduler to use to wait for completionthe other fallback)Completable instance to switch to in case of a timeout,
if null a TimeoutException is emitted insteadReturns a |
| public static @NonNull Completable | |
| public static @NonNull Completable | Returns: the newCompletable instancethe delay time delay, @NonNull TimeUnit the delay unit unit, @NonNull Scheduler the scheduler)Scheduler where to emit the onComplete eventReturns a |
| public final < the resulting object type R> R | Returns: the converted valuethe converter)CompletableConverter that receives the current Completable instance and returns a value to be the result of to()Calls the specified |
| public final < the type of the default item to signal upon completion T> @NonNull CompletionStage | Returns: the newCompletionStage instancethe item to signal upon completion defaultItem)Signals the given default item when the upstream completes or signals the upstream error via
a |
| public final < the value type T> @NonNull Flowable | Returns: the newFlowable instanceReturns a |
| public final @NonNull Future | |
| public final < the value type T> @NonNull Maybe | |
| private static NullPointerException | Returns: the newNullPointerExceptionthe ex)Throwable instance to use as cause, not null (not verified)Creates a |
| public final < the value type T> @NonNull Observable | Returns: the newObservable createdReturns an |
| public final < the value type T> @NonNull Single | Returns: the newSingle instancethe value supplier called when this completionValueSupplier)Completable completes normallyConverts this |
| public final < the value type T> @NonNull Single | Returns: the newSingle instancethe value to emit when this completionValue)Completable completes normallyConverts this |
| public static @NonNull Completable | Returns: the newCompletable instancethe callback which will receive the onSubscribe)CompletableObserver instances
when the Completable is subscribed to.Constructs a |
| public final @NonNull Completable | Returns: the newCompletable instancethe target scheduler)Scheduler where to execute the disposingReturns a |
| public static < the resource type R> @NonNull Completable | Returns: the newCompletable instancethe resourceSupplier, @NonNull Function<? super R, ? extends CompletableSource> Supplier that returns a resource to be managed.the sourceSupplier, @NonNull Consumer<? super R> Function that given a resource returns a CompletableSource instance that will be subscribed tothe resourceCleanup)Consumer that disposes the resource created by the resource supplierReturns a |
| public static < the resource type R> @NonNull Completable | Returns: the newCompletable instancethe resourceSupplier, @NonNull Function<? super R, ? extends CompletableSource> Supplier that returns a resource to be managedthe sourceSupplier, @NonNull Consumer<? super R> Function that given a resource returns a non-null
CompletableSource instance that will be subscribed tothe resourceCleanup, boolean Consumer that disposes the resource created by the resource supplierIf eager)true then resource disposal will happen either on a dispose() call before the upstream is disposed
or just before the emission of a terminal event (onComplete or onError).
If false the resource disposal will happen either on a dispose() call after the upstream is disposed
or just after the emission of a terminal event (onComplete or onError).Returns a |
| public static @NonNull Completable | Returns: the new wrapped or castCompletable instancethe source to wrap source)Wraps the given |