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 SingleObserver#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.observers.DisposableCompletableObserver
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static Completable | Returns: the new Completable instancethe array of source Completables. A subscription to each source will
occur in the same order as in this Iterable. sources)Returns a Completable which terminates as soon as one of the source Completables terminates (normally or with an error) and disposes all other Completables. |
| public static Completable | Returns: the new Completable instancethe array of source Completables. A subscription to each source will
occur in the same order as in this array. sources)Returns a Completable which terminates as soon as one of the source Completables terminates (normally or with an error) and disposes all other Completables. |
| public final Completable | Returns: the new Completable instancethe other Completable, not null. A subscription to this provided source will occur after subscribing
to the current source. other)Returns a Completable that emits the a terminated event of either this Completable or the other Completable whichever fires first. |
| public final < the value type of the next ObservableSource T> Observable | Returns: Observable that composes this Completable and nextthe Observable to subscribe after this Completable is completed, not null next)Returns an Observable which will subscribe to this Completable and once that is completed then
will subscribe to the |
| public final < the value type of the next Publisher T> Flowable | |
| public final < the value type of the next SingleSource T> Single | Returns: Single that composes this Completable and nextthe Single to subscribe after this Completable is completed, not null next)Returns a Single which will subscribe to this Completable and once that is completed then
will subscribe to the |
| public final < the value type of the next MaybeSource T> Maybe | Returns: Maybe that composes this Completable and nextthe Maybe to subscribe after this Completable is completed, not null next)Returns a |
| public final Completable | Returns: the new Completable instancethe other Completable, not null next)Returns a Completable that first runs this Completable and then the other completable. |
| public final < the resulting object type R> R | Returns: the converted valuethe function that receives the current Completable instance and returns a value converter)Calls the specified converter function during assembly time and returns its resulting value. |
| public final void | blockingAwait()
Subscribes to and awaits the termination of this Completable instance in a blocking manner and rethrows any exception emitted. |
| 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, TimeUnit the timeout unit unit)Subscribes to and awaits the termination of this Completable instance in a blocking manner with a specific timeout and rethrows any exception emitted within the timeout window. |
| public final Throwable | Returns: the throwable if this terminated with an error, null otherwiseSubscribes to this Completable instance and blocks until it terminates, then returns null or the emitted exception if any. |
| public final Throwable | Returns: the throwable if this terminated with an error, null otherwisethe timeout value timeout, TimeUnit the time unit unit)Subscribes to this Completable instance and blocks until it terminates or the specified timeout elapses, then returns null for normal termination or the emitted exception if any. |
| public final Completable | Returns: the new Completable instanceSubscribes to this Completable only once, when the first CompletableObserver subscribes to the result Completable, caches its terminal event and relays/replays it to observers. |
| public static Completable | Returns: a Completable instance that completes immediatelyReturns a Completable instance that completes immediately when subscribed to. |
| public final Completable | Returns: the Completable returned by the functionthe transformer function, not null transformer)Calls the given transformer function with this instance and returns the function's resulting Completable. |
| public static Completable | Returns: the Completable instance which completes only when all sources completethe sources to concatenate sources)Returns a Completable which completes only when all sources complete, one after another. |
| public static Completable | Returns: the Completable instance which completes only when all sources completethe sources to concatenate sources)Returns a Completable which completes only when all sources complete, one after another. |
| public static Completable | Returns: the Completable instance which completes only when all sources completethe sources to concatenate sources, int the number of sources to prefetch from the sources prefetch)Returns a Completable which completes only when all sources complete, one after another. |
| public static Completable | Returns: the Completable instance which completes only when all sources completethe sources to concatenate sources)Returns a Completable which completes only when all sources complete, one after another. |
| public final Completable | Returns: the new Completable which subscribes to this and then the other Completablethe other Completable, not null other)Concatenates this Completable with another Completable. |
| public static Completable | Returns: the new Completable instancethe emitter that is called when a CompletableObserver subscribes to the returned source)CompletableProvides an API (via a cold Completable) that bridges the reactive world with the callback-style world. |
| public static Completable | Returns: the Completable instancethe supplier that returns the Completable that will be subscribed to. completableSupplier)Defers the subscription to a Completable instance returned by a supplier. |
| public final Completable | |
| public final Completable | |
| public final Completable | Returns: the new Completable instancethe delay time delay, final TimeUnit the delay unit unit, final Scheduler the scheduler to run the delayed completion on scheduler, final boolean delay the error emission as well? delayError)Returns a Completable which delays the emission of the completion event, and optionally the error as well, by the given time while running on the specified scheduler. |
| public final Completable | Returns: a Completable that delays the subscription to the source CompletableSource by the given amountthe time to delay the subscription delay, TimeUnit the time unit of unit)delayReturns a Completable that delays the subscription to the source CompletableSource by a given amount of time. |
| public final Completable | Returns: a Completable that delays the subscription to the source CompletableSource by a given amount, waiting and subscribing on the given Schedulerthe time to delay the subscription delay, TimeUnit the time unit of unit, Scheduler delaythe Scheduler on which the waiting and subscription will happen scheduler)Returns a Completable that delays the subscription to the source CompletableSource by a given amount of time, both waiting and subscribing on a given Scheduler. |
| public final Completable | Returns: the new Completable instancethe callback to call after this Completable terminates onAfterTerminate)Returns a Completable instance that calls the given onTerminate callback after this Completable completes normally or with an exception. |
| public final Completable | |
| public final Completable | Returns: the new Completable instancethe callback to call when this emits an onComplete event onComplete)Returns a Completable which calls the given onComplete callback if this Completable completes. |
| public final Completable | Returns: the new Completable instancethe action to call when the child subscriber disposes the subscription onDispose)Calls the shared |
| public final Completable | |
| public final Completable | Returns: the new Completable instancethe event callback onEvent)Returns a Completable which calls the given onEvent callback with the (throwable) for an onError or (null) for an onComplete signal from this Completable before delivering said signal to the downstream. |
| private Completable | Returns: the new Completable instancethe consumer called when a CompletableSubscriber subscribes. onSubscribe, final Consumer<? super Throwable> the consumer called when this emits an onError event onError, final Action the runnable called just before when this Completable completes normally onComplete, final Action onTerminate, final Action the runnable called after this Completable completes normally onAfterTerminate, final Action the runnable called when the child disposes the subscription onDispose)Returns a Completable instance that calls the various callbacks on the specific lifecycle events. |
| public final Completable | Returns: the new Completable instancethe callback called when a child subscriber subscribes onSubscribe)Returns a Completable instance that calls the given onSubscribe callback with the disposable that child subscribers receive on subscription. |
| public final Completable | Returns: the new Completable instancethe callback to call just before this Completable terminates onTerminate)Returns a Completable instance that calls the given onTerminate callback just before this Completable completes normally or with an exception. |
| public static Completable | |
| public static Completable | |
| public static Completable | Returns: the new Completable instancethe runnable to run for each subscriber run)Returns a Completable instance that runs the given Action for each subscriber and emits either an unchecked exception or simply completes. |
| public static Completable | Returns: the new Completable instancethe callable instance to execute for each subscriber callable)Returns a Completable which when subscribed, executes the callable function, ignores its normal result and emits onError or onComplete only. |
| public static Completable | Returns: the new Completable instancethe future to react to future)Returns a Completable instance that reacts to the termination of the given Future in a blocking fashion. |
| public static < the value type of the T> CompletableMaybeSource element | Returns: the new Completable instancethe Maybe instance to subscribe to, not null maybe)Returns a Completable instance that when subscribed to, subscribes to the |
| public static < the type of the Observable T> Completable | Returns: the new Completable instancethe Observable instance to subscribe to, not null observable)Returns a Completable instance that subscribes to the given Observable, ignores all values and emits only the terminal event. |
| public static < the type of the publisher T> Completable | Returns: the new Completable instancethe Publisher instance to subscribe to, not null publisher)Returns a Completable instance that subscribes to the given publisher, ignores all values and emits only the terminal event. |
| public static Completable | Returns: the new Completable instancethe runnable to run for each subscriber run)Returns a Completable instance that runs the given Runnable for each subscriber and emits either its exception or simply completes. |
| public static < the value type of the Single T> Completable | Returns: the new Completable instancethe Single instance to subscribe to, not null single)Returns a Completable instance that when subscribed to, subscribes to the Single instance and emits a completion event if the single emits onSuccess or forwards any onError events. |
| public final Completable | Returns: the new Completable instanceHides the identity of this Completable and its Disposable. |
| public final Completable | Returns: the new Completable 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 notification T> Single | Returns: the new Single instanceMaps the signal types of this Completable into a |
| public static Completable | Returns: the new Completable instancethe iterable sequence of sources. sources)Returns a Completable instance that subscribes to all sources at once and completes only when all source Completables complete or one of them emits an error. |
| public static Completable | Returns: the new Completable instancethe iterable sequence of sources. sources)Returns a Completable instance that subscribes to all sources at once and completes only when all source Completables complete or one of them emits an error. |
| public static Completable | Returns: the new Completable instancethe iterable sequence of sources. sources, int the maximum number of concurrent subscriptions maxConcurrency)Returns a Completable instance that keeps subscriptions to a limited number of sources at once and completes only when all source Completables complete or one of them emits an error. |
| private static Completable | Returns: the new Completable instancethe iterable sequence of sources. sources, int the maximum number of concurrent subscriptions maxConcurrency, boolean delay all errors from the main source and from the inner Completables? delayErrors)Returns a Completable instance that keeps subscriptions to a limited number of sources at once and completes only when all source Completables terminate in one way or another, combining any exceptions thrown by either the sources Observable or the inner Completable instances. |
| public static Completable | Returns: the new Completable instancethe iterable sequence of sources. sources)Returns a Completable instance that subscribes to all sources at once and completes only when all source Completables complete or one of them emits an error. |
| public static Completable | Returns: the new Completable instancethe array of Completables sources)Returns a CompletableConsumable that subscribes to all Completables in the source array and delays any error emitted by either the sources observable or any of the inner Completables until all of them terminate in a way or another. |
| public static Completable | Returns: the new Completable instancethe sequence of Completables sources)Returns a Completable that subscribes to all Completables in the source sequence and delays any error emitted by either the sources observable or any of the inner Completables until all of them terminate in a way or another. |
| public static Completable | Returns: the new Completable instancethe sequence of Completables sources)Returns a Completable that subscribes to all Completables in the source sequence and delays any error emitted by either the sources observable or any of the inner Completables until all of them terminate in a way or another. |
| public static Completable | Returns: the new Completable instancethe sequence of Completables sources, int the maximum number of concurrent subscriptions to Completables maxConcurrency)Returns a Completable that subscribes to a limited number of inner Completables at once in the source sequence and delays any error emitted by either the sources observable or any of the inner Completables until all of them terminate in a way or another. |
| public final Completable | Returns: the new Completable instancethe other Completable instance other)Returns a Completable which subscribes to this and the other Completable and completes when both of them complete or one emits an error. |
| public static Completable | Returns: the singleton instance that never calls onError or onCompleteReturns a Completable that never calls onError or onComplete. |
| public final Completable | |
| public final Completable | Returns: the new Completable instanceReturns a Completable instance that if this Completable emits an error, it will emit an onComplete and swallow the throwable. |
| public final Completable | Returns: the new Completable instancethe predicate to call when an Throwable is emitted which should return true
if the Throwable should be swallowed and replaced with an onComplete. predicate)Returns a Completable instance that if this Completable emits an error and the predicate returns true, it will emit an onComplete and swallow the throwable. |
| public final Completable | Returns: the new Completable instancethe mapper function that takes the error and should return a Completable as
continuation. errorMapper)Returns a Completable instance that when encounters an error from this Completable, calls the specified mapper function that returns another Completable instance for it and resumes the execution with it. |
| public final Completable | Returns: a Completable which nulls out references to the upstream producer and downstream CompletableObserver if the sequence is terminated or downstream calls dispose()Nulls out references to the upstream producer and downstream CompletableObserver if the sequence is terminated or downstream calls dispose(). |
| public final Completable | Returns: the new Completable instanceReturns a Completable that repeatedly subscribes to this Completable until disposed. |
| public final Completable | Returns: the new Completable instancethe number of times the resubscription should happen times)Returns a Completable that subscribes repeatedly at most the given times to this Completable. |
| public final Completable | Returns: the new Completable instancethe supplier that should return true to stop resubscribing. stop)Returns a Completable that repeatedly subscribes to this Completable so long as the given stop supplier returns false. |
| public final Completable | Returns: the new Completable instancethe 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 stop handler)Returns a Completable instance that repeats when the Publisher returned by the handler emits an item or completes when this Publisher emits a completed event. |
| public final Completable | Returns: the new Completable instanceReturns a Completable that retries this Completable as long as it emits an onError event. |
| public final Completable | Returns: the new Completable instancethe predicate called when this emits an error with the repeat count and the latest exception
and should return true to retry. predicate)Returns a Completable that retries this Completable in case of an error as long as the predicate returns true. |
| public final Completable | Returns: the new Completable instancethe number of times to resubscribe if the current Completable fails times)Returns a Completable that when this Completable emits an error, retries at most the given number of times before giving up and emitting the last error. |
| public final Completable | Returns: the new Completable instancethe number of times to resubscribe if the current Completable fails times, Predicate<? super Throwable> the predicate that is called with the latest throwable and should return
true to indicate the returned Completable should resubscribe to this Completable. predicate)Returns a Completable that when this Completable emits an error, retries at most times or until the predicate returns false, whichever happens first and emitting the last error. |
| public final Completable | Returns: the new Completable instancethe predicate that is called with the latest throwable and should return
true to indicate the returned Completable should resubscribe to this Completable. predicate)Returns a Completable that when this Completable emits an error, calls the given predicate with the latest exception to decide whether to resubscribe to this or not. |
| public final Completable | Returns: the new Completable instancethe handler that receives a Flowable delivering Throwables and should return a Publisher that
emits items to indicate retries or emits terminal events to indicate termination. handler)Returns a Completable which given a Publisher and when this Completable emits an error, delivers that error through a Flowable and the Publisher should signal a value indicating a retry in response or a terminal event indicating a termination. |
| public final Completable | Returns: the new Completable instancethe other completable to run first other)Returns a Completable which first runs the other Completable then this completable if the other completed normally. |
| public final < the value type T> Observable | Returns: the new Observable instancethe other Observable to run first other)Returns an Observable which first delivers the events of the other Observable then runs this CompletableConsumable. |
| public final < the value type T> Flowable | |
| public final Disposable | Returns: the Disposable that allows disposing the subscriptionSubscribes to this CompletableConsumable and returns a Disposable which can be used to dispose the subscription. |
| public final void | subscribe(CompletableObserver
the CompletableObserver, not null observer)Implements io. |
| public final Disposable | Returns: the Disposable that can be used for disposing the subscription asynchronouslythe runnable that is called if the Completable completes normally onComplete, final Consumer<? super Throwable> the consumer that is called if this Completable emits an error onError)Subscribes to this Completable and calls back either the onError or onComplete functions. |
| public final Disposable | |
| protected abstract void | subscribeActual(CompletableObserver
the CompletableObserver instance, never null observer)Implement this method to handle the incoming |
| public final Completable | Returns: the new Completable instancethe Scheduler to subscribe on scheduler)Returns a Completable which subscribes the child subscriber on the specified scheduler, making sure the subscription side-effects happen on that specific thread of the scheduler. |
| public final < the type of the CompletableObserver to use and return E extends CompletableObserver> E | Returns: the inputobserverthe CompletableObserver (subclass) to use and return, not null observer)Subscribes a given CompletableObserver (subclass) to this Completable and returns the given CompletableObserver as is. |
| public final Completable | Returns: the new Completable instancethe other completable source to observe for the terminal signals other)Terminates the downstream if this or the other |
| public final TestObserver | Returns: the new TestObserver instanceCreates a TestObserver and subscribes it to this Completable. |
| public final TestObserver | Returns: the new TestObserver instanceif true, the TestObserver will be cancelled before subscribing to this
Completable.
cancelled)
Creates a TestObserver optionally in cancelled state, then subscribes it to this Completable. |
| public final Completable | |
| public final Completable | Returns: the new Completable instancethe timeout value timeout, TimeUnit the timeout unit unit, CompletableSource the other Completable instance to switch to in case of a timeout other)Returns a Completable that runs this Completable and switches to the other Completable in case this Completable doesn't complete within the given time. |
| public final Completable | Returns: the new Completable instancethe timeout value timeout, TimeUnit the timeout unit unit, Scheduler the scheduler to use to wait for completion scheduler)Returns a Completable that runs this Completable and emits a TimeoutException in case this Completable doesn't complete within the given time while "waiting" on the specified Scheduler. |
| public final Completable | Returns: the new Completable instancethe timeout value timeout, TimeUnit the timeout unit unit, Scheduler the scheduler to use to wait for completion scheduler, CompletableSource the other Completable instance to switch to in case of a timeout other)Returns a Completable that runs this Completable and switches to the other Completable in case this Completable doesn't complete within the given time while "waiting" on the specified scheduler. |
| private Completable | Returns: the new Completable instancethe timeout value timeout, TimeUnit the timeout unit unit, Scheduler the scheduler to use to wait for completion scheduler, CompletableSource the other Completable instance to switch to in case of a timeout,
if null a TimeoutException is emitted instead other)Returns a Completable that runs this Completable and optionally switches to the other Completable in case this Completable doesn't complete within the given time while "waiting" on the specified scheduler. |
| public static Completable | |
| public static Completable | Returns: the new Completable instancethe delay time delay, final TimeUnit the delay unit unit, final Scheduler the scheduler where to emit the complete event scheduler)Returns a Completable instance that fires its onComplete event after the given delay elapsed by using the supplied scheduler. |
| public final < the output type U> U | Returns: the converted valuethe function called with this which should return some other value. converter)Allows fluent conversion to another type via a function callback. |
| public final < the value type T> Flowable | Returns: the new Flowable instanceReturns a Flowable which when subscribed to subscribes to this Completable and relays the terminal events to the subscriber. |
| public final < the value type T> Maybe | |
| private static NullPointerException | |
| public final < the value type T> Observable | Returns: the new Observable createdReturns an Observable which when subscribed to subscribes to this Completable and relays the terminal events to the subscriber. |
| public final < the value type T> Single | Returns: the new Single instancethe value supplier called when this Completable completes normally completionValueSupplier)Converts this Completable into a Single which when this Completable completes normally, calls the given supplier and emits its returned value through onSuccess. |
| public final < the value type T> Single | Returns: the new Single instancethe value to emit when this Completable completes normally completionValue)Converts this Completable into a Single which when this Completable completes normally, emits the given value through onSuccess. |
| public static Completable | Returns: the created Completable instancethe callback which will receive the CompletableObserver instances
when the Completable is subscribed to. source)Constructs a Completable instance by wrapping the given source callback without any safeguards; you should manage the lifecycle and response to downstream disposal. |
| public final Completable | Returns: the new Completable instancethe target scheduler where to execute the disposing scheduler)Returns a Completable which makes sure when a subscriber disposes the subscription, the dispose is called on the specified scheduler. |
| public static < the resource type R> Completable | Returns: the new Completable instancethe supplier that returns a resource to be managed. resourceSupplier, Function<? super R, ? extends CompletableSource> the function that given a resource returns a Completable instance that will be subscribed to completableFunction, Consumer<? super R> the consumer that disposes the resource created by the resource supplier disposer)Returns a Completable instance which manages a resource along with a custom Completable instance while the subscription is active. |
| public static < the resource type R> Completable | Returns: the new Completable instancethe supplier that returns a resource to be managed resourceSupplier, final Function<? super R, ? extends CompletableSource> the function that given a resource returns a non-null
Completable instance that will be subscribed to completableFunction, final Consumer<? super R> the consumer that disposes the resource created by the resource supplier disposer, final boolean if true, the resource is disposed before the terminal event is emitted, if false, the
resource is disposed after the terminal event has been emitted eager)Returns a Completable instance which manages a resource along with a custom Completable instance while the subscription is active and performs eager or lazy resource disposition. |
| public static Completable | Returns: the source or its wrapper Completablethe source to wrap source)Wraps the given CompletableSource into a Completable if not already Completable. |