public abstract classCompletableextendsObjectimplementsCompletableSource
Completable
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).
TheCompletable
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 theObservable
protocol,onError
andonComplete
are mutually exclusive events.
LikeObservable
, a runningCompletable
can be stopped through theDisposable
instance provided to consumers throughSingleObserver.onSubscribe(io.reactivex.disposables.Disposable)
.
Like anObservable
, aCompletable
is lazy, can be either "hot" or "cold", synchronous or asynchronous.Completable
instances returned by the methods of this class arecold and there is a standardhot implementation in the form of a subject:CompletableSubject
.
The documentation for this class makes use of marble diagrams. The following legend explains these diagrams:
SeeFlowable
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 viasubscribe(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).
DisposableCompletableObserver
Constructor and Description |
---|
Completable() |
Modifier and Type | Method and Description |
---|---|
staticCompletable | amb(Iterable<? extendsCompletableSource> 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. |
staticCompletable | ambArray(CompletableSource... 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. |
Completable | ambWith(CompletableSource other) Returns a Completable that emits the a terminated event of either this Completable or the other Completable whichever fires first. |
Completable | andThen(CompletableSource next) Returns a Completable that first runs this Completable and then the other completable. |
<T> Maybe<T> | andThen(MaybeSource<T> next) Returns a Maybe which will subscribe to this Completable and once that is completed then will subscribe to thenext MaybeSource. |
<T> Observable<T> | andThen(ObservableSource<T> next) Returns an Observable which will subscribe to this Completable and once that is completed then will subscribe to the next ObservableSource. |
<T> Flowable<T> | andThen(Publisher<T> next) Returns a Flowable which will subscribe to this Completable and once that is completed then will subscribe to the next Flowable. |
<T> Single<T> | andThen(SingleSource<T> next) Returns a Single which will subscribe to this Completable and once that is completed then will subscribe to the next SingleSource. |
<R> R | as(CompletableConverter<? extends R> converter) Calls the specified converter function during assembly time and returns its resulting value. |
void | blockingAwait() Subscribes to and awaits the termination of this Completable instance in a blocking manner and rethrows any exception emitted. |
boolean | blockingAwait(long timeout,TimeUnit 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. |
Throwable | blockingGet() Subscribes to this Completable instance and blocks until it terminates, then returns null or the emitted exception if any. |
Throwable | blockingGet(long timeout,TimeUnit 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. |
Completable | cache() Subscribes to this Completable only once, when the first CompletableObserver subscribes to the result Completable, caches its terminal event and relays/replays it to observers. |
staticCompletable | complete() Returns a Completable instance that completes immediately when subscribed to. |
Completable | compose(CompletableTransformer transformer) Calls the given transformer function with this instance and returns the function's resulting Completable. |
staticCompletable | concat(Iterable<? extendsCompletableSource> sources) Returns a Completable which completes only when all sources complete, one after another. |
staticCompletable | concat(Publisher<? extendsCompletableSource> sources) Returns a Completable which completes only when all sources complete, one after another. |
staticCompletable | concat(Publisher<? extendsCompletableSource> sources, int prefetch) Returns a Completable which completes only when all sources complete, one after another. |
staticCompletable | concatArray(CompletableSource... sources) Returns a Completable which completes only when all sources complete, one after another. |
Completable | concatWith(CompletableSource other) Concatenates this Completable with another Completable. |
staticCompletable | create(CompletableOnSubscribe source) Provides an API (via a cold Completable) that bridges the reactive world with the callback-style world. |
staticCompletable | defer(Callable<? extendsCompletableSource> completableSupplier) Defers the subscription to a Completable instance returned by a supplier. |
Completable | delay(long delay,TimeUnit unit) Returns a Completable which delays the emission of the completion event by the given time. |
Completable | delay(long delay,TimeUnit unit,Scheduler scheduler) Returns a Completable which delays the emission of the completion event by the given time while running on the specified scheduler. |
Completable | delay(long delay,TimeUnit unit,Scheduler scheduler, boolean 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. |
Completable | delaySubscription(long delay,TimeUnit unit) Returns a Completable that delays the subscription to the source CompletableSource by a given amount of time. |
Completable | delaySubscription(long delay,TimeUnit unit,Scheduler 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. |
Completable | doAfterTerminate(Action onAfterTerminate) Returns a Completable instance that calls the given onTerminate callback after this Completable completes normally or with an exception. |
Completable | doFinally(Action onFinally) Calls the specified action after this Completable signals onError or onComplete or gets disposed by the downstream. |
Completable | doOnComplete(Action onComplete) Returns a Completable which calls the given onComplete callback if this Completable completes. |
Completable | doOnDispose(Action onDispose) Calls the shared Action if a CompletableObserver subscribed to the current Completable disposes the common Disposable it received via onSubscribe. |
Completable | doOnError(Consumer<? superThrowable> onError) Returns a Completable which calls the given onError callback if this Completable emits an error. |
Completable | doOnEvent(Consumer<? superThrowable> 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. |
Completable | doOnSubscribe(Consumer<? superDisposable> onSubscribe) Returns a Completable instance that calls the given onSubscribe callback with the disposable that child subscribers receive on subscription. |
Completable | doOnTerminate(Action onTerminate) Returns a Completable instance that calls the given onTerminate callback just before this Completable completes normally or with an exception. |
staticCompletable | error(Callable<? extendsThrowable> errorSupplier) Creates a Completable which calls the given error supplier for each subscriber and emits its returned Throwable. |
staticCompletable | error(Throwable error) Creates a Completable instance that emits the given Throwable exception to subscribers. |
staticCompletable | fromAction(Action run) Returns a Completable instance that runs the given Action for each subscriber and emits either an unchecked exception or simply completes. |
staticCompletable | fromCallable(Callable<?> callable) Returns a Completable which when subscribed, executes the callable function, ignores its normal result and emits onError or onComplete only. |
staticCompletable | fromFuture(Future<?> future) Returns a Completable instance that reacts to the termination of the given Future in a blocking fashion. |
static <T> Completable | fromMaybe(MaybeSource<T> maybe) Returns a Completable instance that when subscribed to, subscribes to the Maybe instance and emits a completion event if the maybe emitsonSuccess /onComplete or forwards anyonError events. |
static <T> Completable | fromObservable(ObservableSource<T> observable) Returns a Completable instance that subscribes to the given Observable, ignores all values and emits only the terminal event. |
static <T> Completable | fromPublisher(Publisher<T> publisher) Returns a Completable instance that subscribes to the given publisher, ignores all values and emits only the terminal event. |
staticCompletable | fromRunnable(Runnable run) Returns a Completable instance that runs the given Runnable for each subscriber and emits either its exception or simply completes. |
static <T> Completable | fromSingle(SingleSource<T> 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. |
Completable | hide() Hides the identity of this Completable and its Disposable. |
Completable | lift(CompletableOperator onLift) This method requires advanced knowledge about building operators, please consider other standard composition methods first; Returns a Completable 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. |
<T> Single<Notification<T>> | materialize() Maps the signal types of this Completable into a Notification of the same kind and emits it as a single success value to downstream. |
staticCompletable | merge(Iterable<? extendsCompletableSource> 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. |
staticCompletable | merge(Publisher<? extendsCompletableSource> 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. |
staticCompletable | merge(Publisher<? extendsCompletableSource> sources, int 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. |
staticCompletable | mergeArray(CompletableSource... 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. |
staticCompletable | mergeArrayDelayError(CompletableSource... 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. |
staticCompletable | mergeDelayError(Iterable<? extendsCompletableSource> 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. |
staticCompletable | mergeDelayError(Publisher<? extendsCompletableSource> 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. |
staticCompletable | mergeDelayError(Publisher<? extendsCompletableSource> sources, int 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. |
Completable | mergeWith(CompletableSource other) Returns a Completable which subscribes to this and the other Completable and completes when both of them complete or one emits an error. |
staticCompletable | never() Returns a Completable that never calls onError or onComplete. |
Completable | observeOn(Scheduler scheduler) Returns a Completable which emits the terminal events from the thread of the specified scheduler. |
Completable | onErrorComplete() Returns a Completable instance that if this Completable emits an error, it will emit an onComplete and swallow the throwable. |
Completable | onErrorComplete(Predicate<? superThrowable> 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. |
Completable | onErrorResumeNext(Function<? superThrowable,? extendsCompletableSource> 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. |
Completable | onTerminateDetach() Nulls out references to the upstream producer and downstream CompletableObserver if the sequence is terminated or downstream calls dispose(). |
Completable | repeat() Returns a Completable that repeatedly subscribes to this Completable until disposed. |
Completable | repeat(long times) Returns a Completable that subscribes repeatedly at most the given times to this Completable. |
Completable | repeatUntil(BooleanSupplier stop) Returns a Completable that repeatedly subscribes to this Completable so long as the given stop supplier returns false. |
Completable | repeatWhen(Function<? superFlowable<Object>,? extendsPublisher<?>> 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. |
Completable | retry() Returns a Completable that retries this Completable as long as it emits an onError event. |
Completable | retry(BiPredicate<? superInteger,? superThrowable> predicate) Returns a Completable that retries this Completable in case of an error as long as the predicate returns true. |
Completable | retry(long 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. |
Completable | retry(long times,Predicate<? superThrowable> 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. |
Completable | retry(Predicate<? superThrowable> 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. |
Completable | retryWhen(Function<? superFlowable<Throwable>,? extendsPublisher<?>> 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. |
Completable | startWith(CompletableSource other) Returns a Completable which first runs the other Completable then this completable if the other completed normally. |
<T> Observable<T> | startWith(Observable<T> other) Returns an Observable which first delivers the events of the other Observable then runs this CompletableConsumable. |
<T> Flowable<T> | startWith(Publisher<T> other) Returns a Flowable which first delivers the events of the other Publisher then runs this Completable. |
Disposable | subscribe() Subscribes to this CompletableConsumable and returns a Disposable which can be used to dispose the subscription. |
Disposable | subscribe(Action onComplete) Subscribes to this Completable and calls the given Action when this Completable completes normally. |
Disposable | subscribe(Action onComplete,Consumer<? superThrowable> onError) Subscribes to this Completable and calls back either the onError or onComplete functions. |
void | subscribe(CompletableObserver observer) Subscribes the given CompletableObserver to this CompletableSource instance. |
protected abstract void | subscribeActual(CompletableObserver observer) Implement this method to handle the incoming CompletableObserver s and perform the business logic in your operator. |
Completable | subscribeOn(Scheduler 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. |
<E extendsCompletableObserver> | subscribeWith(E observer) Subscribes a given CompletableObserver (subclass) to this Completable and returns the given CompletableObserver as is. |
Completable | takeUntil(CompletableSource other) Terminates the downstream if this or the other Completable terminates (wins the termination race) while disposing the connection to the losing source. |
TestObserver<Void> | test() Creates a TestObserver and subscribes it to this Completable. |
TestObserver<Void> | test(boolean cancelled) Creates a TestObserver optionally in cancelled state, then subscribes it to this Completable. |
Completable | timeout(long timeout,TimeUnit unit) Returns a Completable that runs this Completable and emits a TimeoutException in case this Completable doesn't complete within the given time. |
Completable | timeout(long timeout,TimeUnit unit,CompletableSource 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. |
Completable | timeout(long timeout,TimeUnit unit,Scheduler 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. |
Completable | timeout(long timeout,TimeUnit unit,Scheduler scheduler,CompletableSource 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. |
staticCompletable | timer(long delay,TimeUnit unit) Returns a Completable instance that fires its onComplete event after the given delay elapsed. |
staticCompletable | timer(long delay,TimeUnit unit,Scheduler scheduler) Returns a Completable instance that fires its onComplete event after the given delay elapsed by using the supplied scheduler. |
<U> U | to(Function<? superCompletable,U> converter) Allows fluent conversion to another type via a function callback. |
<T> Flowable<T> | toFlowable() Returns a Flowable which when subscribed to subscribes to this Completable and relays the terminal events to the subscriber. |
<T> Maybe<T> | toMaybe() Converts this Completable into a Maybe . |
<T> Observable<T> | toObservable() Returns an Observable which when subscribed to subscribes to this Completable and relays the terminal events to the subscriber. |
<T> Single<T> | toSingle(Callable<? extends T> completionValueSupplier) Converts this Completable into a Single which when this Completable completes normally, calls the given supplier and emits its returned value through onSuccess. |
<T> Single<T> | toSingleDefault(T completionValue) Converts this Completable into a Single which when this Completable completes normally, emits the given value through onSuccess. |
staticCompletable | unsafeCreate(CompletableSource source) Constructs a Completable instance by wrapping the given source callbackwithout any safeguards; you should manage the lifecycle and response to downstream disposal. |
Completable | unsubscribeOn(Scheduler scheduler) Returns a Completable which makes sure when a subscriber disposes the subscription, the dispose is called on the specified scheduler. |
static <R> Completable | using(Callable<R> resourceSupplier,Function<? super R,? extendsCompletableSource> completableFunction,Consumer<? super R> disposer) Returns a Completable instance which manages a resource along with a custom Completable instance while the subscription is active. |
static <R> Completable | using(Callable<R> resourceSupplier,Function<? super R,? extendsCompletableSource> completableFunction,Consumer<? super R> disposer, boolean 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. |
staticCompletable | wrap(CompletableSource source) Wraps the given CompletableSource into a Completable if not already Completable. |
@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable ambArray(CompletableSource... sources)
ambArray
does not operate by default on a particularScheduler
.sources
- the array of source Completables. A subscription to each source will occur in the same order as in this array.NullPointerException
- if sources is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable amb(Iterable<? extendsCompletableSource> sources)
amb
does not operate by default on a particularScheduler
.sources
- the array of source Completables. A subscription to each source will occur in the same order as in this Iterable.NullPointerException
- if sources is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable complete()
complete
does not operate by default on a particularScheduler
.@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable concatArray(CompletableSource... sources)
concatArray
does not operate by default on a particularScheduler
.sources
- the sources to concatenateNullPointerException
- if sources is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable concat(Iterable<? extendsCompletableSource> sources)
concat
does not operate by default on a particularScheduler
.sources
- the sources to concatenateNullPointerException
- if sources is null@CheckReturnValue@SchedulerSupport(value="none")@BackpressureSupport(value=FULL)public static Completable concat(Publisher<? extendsCompletableSource> sources)
Completable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well.concat
does not operate by default on a particularScheduler
.sources
- the sources to concatenateNullPointerException
- if sources is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")@BackpressureSupport(value=FULL)public static Completable concat(Publisher<? extendsCompletableSource> sources, int prefetch)
Completable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well.concat
does not operate by default on a particularScheduler
.sources
- the sources to concatenateprefetch
- the number of sources to prefetch from the sourcesNullPointerException
- if sources is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable create(CompletableOnSubscribe source)
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); });
create
does not operate by default on a particularScheduler
.source
- the emitter that is called when a CompletableObserver subscribes to the returnedCompletable
CompletableOnSubscribe
,Cancellable
@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable unsafeCreate(CompletableSource source)
unsafeCreate
does not operate by default on a particularScheduler
.source
- the callback which will receive the CompletableObserver instances when the Completable is subscribed to.NullPointerException
- if source is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable defer(Callable<? extendsCompletableSource> completableSupplier)
defer
does not operate by default on a particularScheduler
.completableSupplier
- the supplier that returns the Completable that will be subscribed to.@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable error(Callable<? extendsThrowable> errorSupplier)
If the errorSupplier returns null, the child CompletableObservers will receive a NullPointerException.
error
does not operate by default on a particularScheduler
.errorSupplier
- the error supplier, not nullNullPointerException
- if errorSupplier is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable error(Throwable error)
error
does not operate by default on a particularScheduler
.error
- the Throwable instance to emit, not nullNullPointerException
- if error is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable fromAction(Action run)
fromAction
does not operate by default on a particularScheduler
.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
.run
- the runnable to run for each subscriberNullPointerException
- if run is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable fromCallable(Callable<?> callable)
fromCallable
does not operate by default on a particularScheduler
.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
.callable
- the callable instance to execute for each subscriber@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable fromFuture(Future<?> future)
Note that if any of the observers to this Completable call dispose, this Completable will cancel the future.
fromFuture
does not operate by default on a particularScheduler
.future
- the future to react to@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static <T> Completable fromMaybe(MaybeSource<T> maybe)
Maybe
instance and emits a completion event if the maybe emitsonSuccess
/onComplete
or forwards anyonError
events.fromMaybe
does not operate by default on a particularScheduler
.History: 2.1.17 - beta
T
- the value type of theMaybeSource
elementmaybe
- the Maybe instance to subscribe to, not nullNullPointerException
- if single is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable fromRunnable(Runnable run)
fromRunnable
does not operate by default on a particularScheduler
.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
.run
- the runnable to run for each subscriberNullPointerException
- if run is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static <T> Completable fromObservable(ObservableSource<T> observable)
fromObservable
does not operate by default on a particularScheduler
.T
- the type of the Observableobservable
- the Observable instance to subscribe to, not nullNullPointerException
- if flowable is null@CheckReturnValue@NonNull@BackpressureSupport(value=UNBOUNDED_IN)@SchedulerSupport(value="none")public static <T> Completable fromPublisher(Publisher<T> publisher)
ThePublisher
must follow theReactive Streams specification. Violating the specification may result in undefined behavior.
If possible, usecreate(CompletableOnSubscribe)
to create a source-likeCompletable
instead.
Note that even thoughPublisher
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.
Completable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well.fromPublisher
does not operate by default on a particularScheduler
.T
- the type of the publisherpublisher
- the Publisher instance to subscribe to, not nullNullPointerException
- if publisher is nullcreate(CompletableOnSubscribe)
@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static <T> Completable fromSingle(SingleSource<T> single)
fromSingle
does not operate by default on a particularScheduler
.T
- the value type of the Singlesingle
- the Single instance to subscribe to, not nullNullPointerException
- if single is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable mergeArray(CompletableSource... sources)
mergeArray
does not operate by default on a particularScheduler
.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.sources
- the iterable sequence of sources.NullPointerException
- if sources is nullmergeArrayDelayError(CompletableSource...)
@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable merge(Iterable<? extendsCompletableSource> sources)
merge
does not operate by default on a particularScheduler
.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.sources
- the iterable sequence of sources.NullPointerException
- if sources is nullmergeDelayError(Iterable)
@CheckReturnValue@SchedulerSupport(value="none")@BackpressureSupport(value=UNBOUNDED_IN)public static Completable merge(Publisher<? extendsCompletableSource> sources)
Completable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well.merge
does not operate by default on a particularScheduler
.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.sources
- the iterable sequence of sources.NullPointerException
- if sources is nullmergeDelayError(Publisher)
@CheckReturnValue@SchedulerSupport(value="none")@BackpressureSupport(value=FULL)public static Completable merge(Publisher<? extendsCompletableSource> sources, int maxConcurrency)
Completable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well.merge
does not operate by default on a particularScheduler
.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.sources
- the iterable sequence of sources.maxConcurrency
- the maximum number of concurrent subscriptionsNullPointerException
- if sources is nullIllegalArgumentException
- if maxConcurrency is less than 1mergeDelayError(Publisher, int)
@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable mergeArrayDelayError(CompletableSource... sources)
mergeArrayDelayError
does not operate by default on a particularScheduler
.sources
- the array of CompletablesNullPointerException
- if sources is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable mergeDelayError(Iterable<? extendsCompletableSource> sources)
mergeDelayError
does not operate by default on a particularScheduler
.sources
- the sequence of CompletablesNullPointerException
- if sources is null@CheckReturnValue@SchedulerSupport(value="none")@BackpressureSupport(value=UNBOUNDED_IN)public static Completable mergeDelayError(Publisher<? extendsCompletableSource> sources)
Completable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well.mergeDelayError
does not operate by default on a particularScheduler
.sources
- the sequence of CompletablesNullPointerException
- if sources is null@CheckReturnValue@SchedulerSupport(value="none")@BackpressureSupport(value=FULL)public static Completable mergeDelayError(Publisher<? extendsCompletableSource> sources, int maxConcurrency)
Completable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well.mergeDelayError
does not operate by default on a particularScheduler
.sources
- the sequence of CompletablesmaxConcurrency
- the maximum number of concurrent subscriptions to CompletablesNullPointerException
- if sources is null@CheckReturnValue@SchedulerSupport(value="none")public static Completable never()
never
does not operate by default on a particularScheduler
.@CheckReturnValue@SchedulerSupport(value="io.reactivex:computation")public static Completable timer(long delay,TimeUnit unit)
timer
does operate by default on thecomputation
Scheduler
.delay
- the delay timeunit
- the delay unit@CheckReturnValue@NonNull@SchedulerSupport(value="custom")public static Completable timer(long delay,TimeUnit unit,Scheduler scheduler)
timer
operates on theScheduler
you specify.delay
- the delay timeunit
- the delay unitscheduler
- the scheduler where to emit the complete event@CheckReturnValue@SchedulerSupport(value="none")public static <R> Completable using(Callable<R> resourceSupplier,Function<? super R,? extendsCompletableSource> completableFunction,Consumer<? super R> disposer)
This overload disposes eagerly before the terminal event is emitted.
using
does not operate by default on a particularScheduler
.R
- the resource typeresourceSupplier
- the supplier that returns a resource to be managed.completableFunction
- the function that given a resource returns a Completable instance that will be subscribed todisposer
- the consumer that disposes the resource created by the resource supplier@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static <R> Completable using(Callable<R> resourceSupplier,Function<? super R,? extendsCompletableSource> completableFunction,Consumer<? super R> disposer, boolean eager)
If this overload performs a lazy disposal after the terminal event is emitted. Exceptions thrown at this time will be delivered to RxJavaPlugins only.
using
does not operate by default on a particularScheduler
.R
- the resource typeresourceSupplier
- the supplier that returns a resource to be managedcompletableFunction
- the function that given a resource returns a non-null Completable instance that will be subscribed todisposer
- the consumer that disposes the resource created by the resource suppliereager
- 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@CheckReturnValue@NonNull@SchedulerSupport(value="none")public static Completable wrap(CompletableSource source)
wrap
does not operate by default on a particularScheduler
.source
- the source to wrapNullPointerException
- if source is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final Completable ambWith(CompletableSource other)
ambWith
does not operate by default on a particularScheduler
.other
- the other Completable, not null. A subscription to this provided source will occur after subscribing to the current source.NullPointerException
- if other is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final <T> Observable<T> andThen(ObservableSource<T> next)
next
ObservableSource. An error event from this Completable will be propagated to the downstream subscriber and will result in skipping the subscription of the Observable.andThen
does not operate by default on a particularScheduler
.T
- the value type of the next ObservableSourcenext
- the Observable to subscribe after this Completable is completed, not nullNullPointerException
- if next is null@CheckReturnValue@NonNull@BackpressureSupport(value=FULL)@SchedulerSupport(value="none")public final <T> Flowable<T> andThen(Publisher<T> next)
next
Flowable. An error event from this Completable will be propagated to the downstream subscriber and will result in skipping the subscription of the Publisher.Flowable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well.andThen
does not operate by default on a particularScheduler
.T
- the value type of the next Publishernext
- the Publisher to subscribe after this Completable is completed, not nullNullPointerException
- if next is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final <T> Single<T> andThen(SingleSource<T> next)
next
SingleSource. An error event from this Completable will be propagated to the downstream subscriber and will result in skipping the subscription of the Single.andThen
does not operate by default on a particularScheduler
.T
- the value type of the next SingleSourcenext
- the Single to subscribe after this Completable is completed, not null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final <T> Maybe<T> andThen(MaybeSource<T> next)
Maybe
which will subscribe to this Completable and once that is completed then will subscribe to thenext
MaybeSource. An error event from this Completable will be propagated to the downstream subscriber and will result in skipping the subscription of the Maybe.andThen
does not operate by default on a particularScheduler
.T
- the value type of the next MaybeSourcenext
- the Maybe to subscribe after this Completable is completed, not null@CheckReturnValue@SchedulerSupport(value="none")public final Completable andThen(CompletableSource next)
This is an alias forconcatWith(CompletableSource)
.
andThen
does not operate by default on a particularScheduler
.next
- the other Completable, not nullNullPointerException
- if other is null@CheckReturnValue@SchedulerSupport(value="none")public final <R> R as(@NonNullCompletableConverter<? extends R> converter)
This allows fluent conversion to any other type.
as
does not operate by default on a particularScheduler
.History: 2.1.7 - experimental
R
- the resulting object typeconverter
- the function that receives the current Completable instance and returns a valueNullPointerException
- if converter is null@SchedulerSupport(value="none")public final void blockingAwait()
blockingAwait
does not operate by default on a particularScheduler
.Exception
intoRuntimeException
and throws that. Otherwise,RuntimeException
s andError
s are rethrown as they are.RuntimeException
- wrapping an InterruptedException if the current thread is interrupted@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final boolean blockingAwait(long timeout,TimeUnit unit)
blockingAwait
does not operate by default on a particularScheduler
.Exception
intoRuntimeException
and throws that. Otherwise,RuntimeException
s andError
s are rethrown as they are.timeout
- the timeout valueunit
- the timeout unitRuntimeException
- wrapping an InterruptedException if the current thread is interrupted@Nullable@CheckReturnValue@SchedulerSupport(value="none")public final Throwable blockingGet()
blockingGet
does not operate by default on a particularScheduler
.RuntimeException
- that wraps an InterruptedException if the wait is interrupted@Nullable@CheckReturnValue@SchedulerSupport(value="none")public final Throwable blockingGet(long timeout,TimeUnit unit)
blockingGet
does not operate by default on a particularScheduler
.timeout
- the timeout valueunit
- the time unitRuntimeException
- that wraps an InterruptedException if the wait is interrupted or TimeoutException if the specified timeout elapsed before it@CheckReturnValue@SchedulerSupport(value="none")public final Completable cache()
Note that this operator doesn't allow disposing the connection of the upstream source.
cache
does not operate by default on a particularScheduler
.History: 2.0.4 - experimental
@CheckReturnValue@SchedulerSupport(value="none")public final Completable compose(CompletableTransformer transformer)
compose
does not operate by default on a particularScheduler
.transformer
- the transformer function, not nullNullPointerException
- if transformer is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final Completable concatWith(CompletableSource other)
concatWith
does not operate by default on a particularScheduler
.other
- the other Completable, not nullNullPointerException
- if other is nullandThen(MaybeSource)
,andThen(ObservableSource)
,andThen(SingleSource)
,andThen(Publisher)
@CheckReturnValue@SchedulerSupport(value="io.reactivex:computation")public final Completable delay(long delay,TimeUnit unit)
delay
does operate by default on thecomputation
Scheduler
.delay
- the delay timeunit
- the delay unitNullPointerException
- if unit is null@CheckReturnValue@SchedulerSupport(value="custom")public final Completable delay(long delay,TimeUnit unit,Scheduler scheduler)
delay
operates on theScheduler
you specify.delay
- the delay timeunit
- the delay unitscheduler
- the scheduler to run the delayed completion onNullPointerException
- if unit or scheduler is null@CheckReturnValue@NonNull@SchedulerSupport(value="custom")public final Completable delay(long delay,TimeUnit unit,Scheduler scheduler, boolean delayError)
delay
operates on theScheduler
you specify.delay
- the delay timeunit
- the delay unitscheduler
- the scheduler to run the delayed completion ondelayError
- delay the error emission as well?NullPointerException
- if unit or scheduler is null@CheckReturnValue@SchedulerSupport(value="io.reactivex:computation")public final Completable delaySubscription(long delay,TimeUnit unit)
delaySubscription
operates by default on thecomputation
Scheduler
.delay
- the time to delay the subscriptionunit
- the time unit ofdelay
@CheckReturnValue@SchedulerSupport(value="custom")public final Completable delaySubscription(long delay,TimeUnit unit,Scheduler scheduler)
Scheduler
this operator will use.delay
- the time to delay the subscriptionunit
- the time unit ofdelay
scheduler
- the Scheduler on which the waiting and subscription will happen@CheckReturnValue@SchedulerSupport(value="none")public final Completable doOnComplete(Action onComplete)
doOnComplete
does not operate by default on a particularScheduler
.onComplete
- the callback to call when this emits an onComplete eventNullPointerException
- if onComplete is nulldoFinally(Action)
@CheckReturnValue@SchedulerSupport(value="none")public final Completable doOnDispose(Action onDispose)
Action
if a CompletableObserver subscribed to the current Completable disposes the common Disposable it received via onSubscribe.doOnDispose
does not operate by default on a particularScheduler
.onDispose
- the action to call when the child subscriber disposes the subscriptionNullPointerException
- if onDispose is null@CheckReturnValue@SchedulerSupport(value="none")public final Completable doOnError(Consumer<? superThrowable> onError)
doOnError
does not operate by default on a particularScheduler
.onError
- the error callbackNullPointerException
- if onError is nulldoFinally(Action)
@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final Completable doOnEvent(Consumer<? superThrowable> onEvent)
doOnEvent
does not operate by default on a particularScheduler
.onEvent
- the event callbackNullPointerException
- if onEvent is null@CheckReturnValue@SchedulerSupport(value="none")public final Completable doOnSubscribe(Consumer<? superDisposable> onSubscribe)
doOnSubscribe
does not operate by default on a particularScheduler
.onSubscribe
- the callback called when a child subscriber subscribesNullPointerException
- if onSubscribe is null@CheckReturnValue@SchedulerSupport(value="none")public final Completable doOnTerminate(Action onTerminate)
doOnTerminate
does not operate by default on a particularScheduler
.onTerminate
- the callback to call just before this Completable terminatesdoFinally(Action)
@CheckReturnValue@SchedulerSupport(value="none")public final Completable doAfterTerminate(Action onAfterTerminate)
doAfterTerminate
does not operate by default on a particularScheduler
.onAfterTerminate
- the callback to call after this Completable terminatesdoFinally(Action)
@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final Completable doFinally(Action onFinally)
In case of a race between a terminal event and a dispose call, the providedonFinally
action is executed once per subscription.
Note that theonFinally
action is shared between subscriptions and as such should be thread-safe.
doFinally
does not operate by default on a particularScheduler
.History: 2.0.1 - experimental
onFinally
- the action called when this Completable terminates or gets disposed@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final Completable lift(CompletableOperator onLift)
Completable
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 newCompletableObserver
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 theRxJava wiki: Writing operators page about the tools, requirements, rules, considerations and pitfalls of implementing them.
Note that implementing custom operators via thislift()
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 inlift()
as theapply()
method requires a non-nullCompletableObserver
instance to be returned, which is then unconditionally subscribed to the upstreamCompletable
. 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.CompletableObserver)
can decide to not subscribe to its upstream after all.
lift
does not operate by default on a particularScheduler
, however, theCompletableOperator
may use aScheduler
to support its own asynchronous behavior.onLift
- theCompletableOperator
that receives the downstream'sCompletableObserver
and should return aCompletableObserver
with custom behavior to be used as the consumer for the currentCompletable
.compose(CompletableTransformer)
@CheckReturnValue@SchedulerSupport(value="none")public final <T> Single<Notification<T>> materialize()
Notification
of the same kind and emits it as a single success value to downstream.materialize
does not operate by default on a particularScheduler
.T
- the intended target element type of the notificationSingle.dematerialize(Function)
@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final Completable mergeWith(CompletableSource other)
mergeWith
does not operate by default on a particularScheduler
.other
- the other Completable instanceNullPointerException
- if other is null@CheckReturnValue@NonNull@SchedulerSupport(value="custom")public final Completable observeOn(Scheduler scheduler)
observeOn
operates on aScheduler
you specify.scheduler
- the scheduler to emit terminal events onNullPointerException
- if scheduler is null@CheckReturnValue@SchedulerSupport(value="none")public final Completable onErrorComplete()
onErrorComplete
does not operate by default on a particularScheduler
.@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final Completable onErrorComplete(Predicate<? superThrowable> predicate)
onErrorComplete
does not operate by default on a particularScheduler
.predicate
- the predicate to call when an Throwable is emitted which should return true if the Throwable should be swallowed and replaced with an onComplete.@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final Completable onErrorResumeNext(Function<? superThrowable,? extendsCompletableSource> errorMapper)
onErrorResumeNext
does not operate by default on a particularScheduler
.errorMapper
- the mapper function that takes the error and should return a Completable as continuation.@CheckReturnValue@SchedulerSupport(value="none")public final Completable onTerminateDetach()
onTerminateDetach
does not operate by default on a particularScheduler
.History: 2.1.5 - experimental
@CheckReturnValue@SchedulerSupport(value="none")public final Completable repeat()
repeat
does not operate by default on a particularScheduler
.@CheckReturnValue@SchedulerSupport(value="none")public final Completable repeat(long times)
repeat
does not operate by default on a particularScheduler
.times
- the number of times the resubscription should happenIllegalArgumentException
- if times is less than zero@CheckReturnValue@SchedulerSupport(value="none")public final Completable repeatUntil(BooleanSupplier stop)
repeatUntil
does not operate by default on a particularScheduler
.stop
- the supplier that should return true to stop resubscribing.NullPointerException
- if stop is null@CheckReturnValue@SchedulerSupport(value="none")public final Completable repeatWhen(Function<? superFlowable<Object>,? extendsPublisher<?>> handler)
repeatWhen
does not operate by default on a particularScheduler
.handler
- the 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 stopNullPointerException
- if stop is null@CheckReturnValue@SchedulerSupport(value="none")public final Completable retry()
retry
does not operate by default on a particularScheduler
.@CheckReturnValue@SchedulerSupport(value="none")public final Completable retry(BiPredicate<? superInteger,? superThrowable> predicate)
retry
does not operate by default on a particularScheduler
.predicate
- the predicate called when this emits an error with the repeat count and the latest exception and should return true to retry.@CheckReturnValue@SchedulerSupport(value="none")public final Completable retry(long times)
retry
does not operate by default on a particularScheduler
.times
- the number of times to resubscribe if the current Completable failsIllegalArgumentException
- if times is negative@CheckReturnValue@SchedulerSupport(value="none")public final Completable retry(long times,Predicate<? superThrowable> predicate)
retry
does not operate by default on a particularScheduler
.History: 2.1.8 - experimental
times
- the number of times to resubscribe if the current Completable failspredicate
- the predicate that is called with the latest throwable and should return true to indicate the returned Completable should resubscribe to this Completable.NullPointerException
- if predicate is nullIllegalArgumentException
- if times is negative@CheckReturnValue@SchedulerSupport(value="none")public final Completable retry(Predicate<? superThrowable> predicate)
retry
does not operate by default on a particularScheduler
.predicate
- the predicate that is called with the latest throwable and should return true to indicate the returned Completable should resubscribe to this Completable.NullPointerException
- if predicate is null@CheckReturnValue@SchedulerSupport(value="none")public final Completable retryWhen(Function<? superFlowable<Throwable>,? extendsPublisher<?>> handler)
Note that the innerPublisher
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, signalling onNext followed by onComplete 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();
retryWhen
does not operate by default on a particularScheduler
.handler
- the 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.NullPointerException
- if handler is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final Completable startWith(CompletableSource other)
startWith
does not operate by default on a particularScheduler
.other
- the other completable to run firstNullPointerException
- if other is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final <T> Observable<T> startWith(Observable<T> other)
startWith
does not operate by default on a particularScheduler
.T
- the value typeother
- the other Observable to run firstNullPointerException
- if other is null@CheckReturnValue@NonNull@BackpressureSupport(value=FULL)@SchedulerSupport(value="none")public final <T> Flowable<T> startWith(Publisher<T> other)
Flowable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well.startWith
does not operate by default on a particularScheduler
.T
- the value typeother
- the other Publisher to run firstNullPointerException
- if other is null@CheckReturnValue@SchedulerSupport(value="none")public final Completable hide()
Allows preventing certain identity-based optimizations (fusion).
hide
does not operate by default on a particularScheduler
.History: 2.0.5 - experimental
@SchedulerSupport(value="none")public final Disposable subscribe()
subscribe
does not operate by default on a particularScheduler
.@SchedulerSupport(value="none")public final void subscribe(CompletableObserver observer)
CompletableSource
subscribe
in interface CompletableSource
observer
- the CompletableObserver, not nullprotected abstract void subscribeActual(CompletableObserver observer)
CompletableObserver
s and perform the business logic in your operator.There is no need to call any of the plugin hooks on the currentCompletable
instance or theCompletableObserver
; all hooks and basic safeguards have been applied bysubscribe(CompletableObserver)
before this method gets called.
observer
- the CompletableObserver instance, never null@CheckReturnValue@SchedulerSupport(value="none")public final <E extendsCompletableObserver> E subscribeWith(E observer)
Usage example:
Completable source = Completable.complete().delay(1, TimeUnit.SECONDS); CompositeDisposable composite = new CompositeDisposable(); DisposableCompletableObserver ds = new DisposableCompletableObserver() { // ... }; composite.add(source.subscribeWith(ds));
subscribeWith
does not operate by default on a particularScheduler
.E
- the type of the CompletableObserver to use and returnobserver
- the CompletableObserver (subclass) to use and return, not nullobserver
NullPointerException
- ifobserver
is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final Disposable subscribe(Action onComplete,Consumer<? superThrowable> onError)
subscribe
does not operate by default on a particularScheduler
.onComplete
- the runnable that is called if the Completable completes normallyonError
- the consumer that is called if this Completable emits an errorNullPointerException
- if either callback is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final Disposable subscribe(Action onComplete)
If the Completable emits an error, it is wrapped into anOnErrorNotImplementedException
and routed to the RxJavaPlugins.onError handler.
subscribe
does not operate by default on a particularScheduler
.onComplete
- the runnable called when this Completable completes normally@CheckReturnValue@NonNull@SchedulerSupport(value="custom")public final Completable subscribeOn(Scheduler scheduler)
subscribeOn
operates on aScheduler
you specify.scheduler
- the Scheduler to subscribe onNullPointerException
- if scheduler is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final Completable takeUntil(CompletableSource other)
Completable
terminates (wins the termination race) while disposing the connection to the losing source.takeUntil
does not operate by default on a particularScheduler
.RxJavaPlugins.onError(Throwable)
.History: 2.1.17 - experimental
other
- the other completable source to observe for the terminal signals@CheckReturnValue@SchedulerSupport(value="io.reactivex:computation")public final Completable timeout(long timeout,TimeUnit unit)
timeout
signals the TimeoutException on thecomputation
Scheduler
.timeout
- the timeout valueunit
- the timeout unitNullPointerException
- if unit is null@CheckReturnValue@NonNull@SchedulerSupport(value="io.reactivex:computation")public final Completable timeout(long timeout,TimeUnit unit,CompletableSource other)
timeout
subscribes to the other CompletableSource on thecomputation
Scheduler
.timeout
- the timeout valueunit
- the timeout unitother
- the other Completable instance to switch to in case of a timeoutNullPointerException
- if unit or other is null@CheckReturnValue@SchedulerSupport(value="custom")public final Completable timeout(long timeout,TimeUnit unit,Scheduler scheduler)
timeout
signals the TimeoutException on theScheduler
you specify.timeout
- the timeout valueunit
- the timeout unitscheduler
- the scheduler to use to wait for completionNullPointerException
- if unit or scheduler is null@CheckReturnValue@NonNull@SchedulerSupport(value="custom")public final Completable timeout(long timeout,TimeUnit unit,Scheduler scheduler,CompletableSource other)
timeout
subscribes to the other CompletableSource on theScheduler
you specify.timeout
- the timeout valueunit
- the timeout unitscheduler
- the scheduler to use to wait for completionother
- the other Completable instance to switch to in case of a timeoutNullPointerException
- if unit, scheduler or other is null@CheckReturnValue@SchedulerSupport(value="none")public final <U> U to(Function<? superCompletable,U> converter)
to
does not operate by default on a particularScheduler
.U
- the output typeconverter
- the function called with this which should return some other value.NullPointerException
- if converter is null@CheckReturnValue@BackpressureSupport(value=FULL)@SchedulerSupport(value="none")public final <T> Flowable<T> toFlowable()
Flowable
honors the backpressure of the downstream consumer.toFlowable
does not operate by default on a particularScheduler
.T
- the value type@CheckReturnValue@SchedulerSupport(value="none")public final <T> Maybe<T> toMaybe()
Maybe
.toMaybe
does not operate by default on a particularScheduler
.T
- the value typeMaybe
that only callsonComplete
oronError
, based on which one is called by the source Completable.@CheckReturnValue@SchedulerSupport(value="none")public final <T> Observable<T> toObservable()
toObservable
does not operate by default on a particularScheduler
.T
- the value type@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final <T> Single<T> toSingle(Callable<? extends T> completionValueSupplier)
toSingle
does not operate by default on a particularScheduler
.T
- the value typecompletionValueSupplier
- the value supplier called when this Completable completes normallyNullPointerException
- if completionValueSupplier is null@CheckReturnValue@NonNull@SchedulerSupport(value="none")public final <T> Single<T> toSingleDefault(T completionValue)
toSingleDefault
does not operate by default on a particularScheduler
.T
- the value typecompletionValue
- the value to emit when this Completable completes normallyNullPointerException
- if completionValue is null@CheckReturnValue@NonNull@SchedulerSupport(value="custom")public final Completable unsubscribeOn(Scheduler scheduler)
unsubscribeOn
calls dispose() of the upstream on theScheduler
you specify.scheduler
- the target scheduler where to execute the disposingNullPointerException
- if scheduler is null@CheckReturnValue@SchedulerSupport(value="none")public final TestObserver<Void> test()
test
does not operate by default on a particularScheduler
.@CheckReturnValue@SchedulerSupport(value="none")public final TestObserver<Void> test(boolean cancelled)
cancelled
- if true, the TestObserver will be cancelled before subscribing to this Completable.test
does not operate by default on a particularScheduler
.