Package rx
Class Completable
java.lang.Object
rx.Completable
Represents a deferred computation without any value but only indication for completion or exception.
The class follows a similar event pattern as Reactive-Streams: onSubscribe (onError|onComplete)?
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Callback used for building deferred computations that takes a CompletableSubscriber.static interface
Convenience interface and callback used by the lift operator that given a child CompletableSubscriber, return a parent CompletableSubscriber that does any kind of lifecycle-related transformations.static interface
Represents the subscription API callbacks when subscribing to a Completable instance.static interface
Convenience interface and callback used by the compose operator to turn a Completable into another Completable fluently. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final Completable
Single instance of a complete Completable.(package private) static final Completable
Single instance of a never Completable.private final Completable.CompletableOnSubscribe
The actual subscription action. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Completable
(Completable.CompletableOnSubscribe onSubscribe) Constructs a Completable instance with the given onSubscribe callback.private
Completable
(Completable.CompletableOnSubscribe onSubscribe, boolean useHook) Constructs a Completable instance with the given onSubscribe callback without calling the onCreate hook. -
Method Summary
Modifier and TypeMethodDescriptionstatic Completable
amb
(Iterable<? extends Completable> sources) Returns a Completable which terminates as soon as one of the source Completables terminates (normally or with an error) and cancels all other Completables.static Completable
amb
(Completable... sources) Returns a Completable which terminates as soon as one of the source Completables terminates (normally or with an error) and cancels all other Completables.final Completable
ambWith
(Completable other) Returns a Completable that emits the a terminated event of either this Completable or the other Completable whichever fires first.final Completable
andThen
(Completable next) Returns a completable that first runs this Completable and then the other completable.final <T> Observable
<T> andThen
(Observable<T> next) Returns an Observable which will subscribe to this Completable and once that is completed then will subscribe to thenext
Observable.final <T> Single
<T> Returns a Single which will subscribe to this Completable and once that is completed then will subscribe to thenext
Single.final void
await()
Subscribes to and awaits the termination of this Completable instance in a blocking manner and rethrows any exception emitted.final boolean
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.static Completable
complete()
Returns a Completable instance that completes immediately when subscribed to.final Completable
compose
(Completable.CompletableTransformer transformer) Calls the given transformer function with this instance and returns the function's resulting Completable.static Completable
concat
(Iterable<? extends Completable> sources) Returns a Completable which completes only when all sources complete, one after another.static Completable
concat
(Completable... sources) Returns a Completable which completes only when all sources complete, one after another.static Completable
concat
(Observable<? extends Completable> sources) Returns a Completable which completes only when all sources complete, one after another.static Completable
concat
(Observable<? extends Completable> sources, int prefetch) Returns a Completable which completes only when all sources complete, one after another.final Completable
concatWith
(Completable other) Concatenates this Completable with another Completable.static Completable
create
(Completable.CompletableOnSubscribe onSubscribe) Constructs a Completable instance by wrapping the given onSubscribe callback.static Completable
defer
(Func0<? extends Completable> completableFunc0) Defers the subscription to a Completable instance returned by a supplier.final Completable
Returns a Completable which delays the emission of the completion event by the given time.final Completable
Returns a Completable which delays the emission of the completion event by the given time while running on the specified scheduler.final Completable
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.private static void
final Completable
doAfterTerminate
(Action0 onAfterComplete) Returns a Completable instance that calls the given onAfterComplete callback after this Completable completes normally.final Completable
doOnComplete
(Action0 onComplete) Deprecated.final Completable
doOnCompleted
(Action0 onCompleted) Returns a Completable which calls the given onCompleted callback if this Completable completes.final Completable
Returns a Completable which calls the given onError callback if this Completable emits an error.protected final Completable
doOnLifecycle
(Action1<? super Subscription> onSubscribe, Action1<? super Throwable> onError, Action0 onComplete, Action0 onAfterComplete, Action0 onUnsubscribe) Returns a Completable instance that calls the various callbacks on the specific lifecycle events.final Completable
doOnSubscribe
(Action1<? super Subscription> onSubscribe) Returns a Completable instance that calls the given onSubscribe callback with the disposable that child subscribers receive on subscription.final Completable
doOnTerminate
(Action0 onTerminate) Returns a Completable instance that calls the given onTerminate callback just before this Completable completes normally or with an exceptionfinal Completable
doOnUnsubscribe
(Action0 onUnsubscribe) Returns a Completable which calls the given onUnsubscribe callback if the child subscriber cancels the subscription.final Completable
endWith
(Completable other) Deprecated.UseandThen(rx.Completable)
instead.final <T> Observable
<T> endWith
(Observable<T> next) Deprecated.UseandThen(rx.Observable)
instead.static Completable
Creates a Completable instance that emits the given Throwable exception to subscribers.static Completable
Creates a Completable which calls the given error supplier for each subscriber and emits its returned Throwable.static Completable
fromAction
(Action0 action) Returns a Completable instance that runs the given Action0 for each subscriber and emits either an unchecked exception or simply completes.static Completable
fromCallable
(Callable<?> callable) Returns a Completable which when subscribed, executes the callable function, ignores its normal result and emits onError or onCompleted only.static Completable
fromFuture
(Future<?> future) Returns a Completable instance that reacts to the termination of the given Future in a blocking fashion.static Completable
fromObservable
(Observable<?> flowable) Returns a Completable instance that subscribes to the given flowable, ignores all values and emits only the terminal event.static Completable
fromSingle
(Single<?> 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.final Throwable
get()
Subscribes to this Completable instance and blocks until it terminates, then returns null or the emitted exception if any.final Throwable
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.final Completable
lift
(Completable.CompletableOperator onLift) Lifts a CompletableSubscriber transformation into the chain of Completables.static Completable
merge
(Iterable<? extends Completable> 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.static Completable
merge
(Completable... 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.static Completable
merge
(Observable<? extends Completable> 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.static Completable
merge
(Observable<? extends Completable> 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.protected static Completable
merge0
(Observable<? extends Completable> sources, int maxConcurrency, boolean 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.static Completable
mergeDelayError
(Iterable<? extends Completable> 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.static Completable
mergeDelayError
(Completable... sources) Returns a Completable 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.static Completable
mergeDelayError
(Observable<? extends Completable> 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.static Completable
mergeDelayError
(Observable<? extends Completable> 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.final Completable
mergeWith
(Completable other) Returns a Completable which subscribes to this and the other Completable and completes when both of them complete or one emits an error.static Completable
never()
Returns a Completable that never calls onError or onComplete.final Completable
Returns a Completable which emits the terminal events from the thread of the specified scheduler.final Completable
Returns a Completable instance that if this Completable emits an error, it will emit an onComplete and swallow the throwable.final Completable
onErrorComplete
(Func1<? super Throwable, Boolean> 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.final Completable
onErrorResumeNext
(Func1<? super Throwable, ? extends Completable> 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.final Completable
repeat()
Returns a Completable that repeatedly subscribes to this Completable until cancelled.final Completable
repeat
(long times) Returns a Completable that subscribes repeatedly at most the given times to this Completable.final Completable
repeatWhen
(Func1<? super Observable<? extends Void>, ? extends Observable<?>> 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.(package private) static <T> T
requireNonNull
(T o) Java 7 backport: throws a NullPointerException if o is null.final Completable
retry()
Returns a Completable that retries this Completable as long as it emits an onError event.final 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.final Completable
Returns a Completable that retries this Completable in case of an error as long as the predicate returns true.final Completable
retryWhen
(Func1<? super Observable<? extends Throwable>, ? extends Observable<?>> handler) Returns a Completable which given a Publisher and when this Completable emits an error, delivers that error through an Observable and the Publisher should return a value indicating a retry in response or a terminal event indicating a termination.final Completable
startWith
(Completable other) Returns a Completable which first runs the other Completable then this completable if the other completed normally.final <T> Observable
<T> startWith
(Observable<T> other) Returns an Observable which first delivers the events of the other Observable then runs this Completable.final Subscription
Subscribes to this Completable and returns a Subscription which can be used to cancel the subscription.final void
Subscribes the given CompletableSubscriber to this Completable instance and handles exceptions thrown by its onXXX methods.final Subscription
Subscribes to this Completable and calls the given Action0 when this Completable completes normally.final Subscription
Subscribes to this Completable and calls back either the onError or onComplete functions.final <T> void
subscribe
(Subscriber<T> s) Subscribes a regular Subscriber to this Completable instance which will receive only an onError or onComplete event and handles exceptions thrown by its onXXX methods.final 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.final Completable
Returns a Completable that runs this Completable and emits a TimeoutException in case this Completable doesn't complete within the given time.final Completable
timeout
(long timeout, TimeUnit unit, Completable 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.final Completable
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.final Completable
timeout
(long timeout, TimeUnit unit, Scheduler scheduler, Completable 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.final Completable
timeout0
(long timeout, TimeUnit unit, Scheduler scheduler, Completable 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.static Completable
Returns a Completable instance that fires its onComplete event after the given delay elapsed.static Completable
Returns a Completable instance that fires its onCompleted event after the given delay elapsed by using the supplied scheduler.final <U> U
to
(Func1<? super Completable, U> converter) Allows fluent conversion to another type via a function callback.(package private) static NullPointerException
Creates a NullPointerException instance and sets the given Throwable as its initial cause.final <T> Observable
<T> Returns an Observable which when subscribed to subscribes to this Completable and relays the terminal events to the subscriber.final <T> Single
<T> Converts this Completable into a Single which when this Completable completes normally, calls the given supplier and emits its returned value through onSuccess.final <T> Single
<T> toSingleDefault
(T completionValue) Converts this Completable into a Single which when this Completable completes normally, emits the given value through onSuccess.final void
Subscribes the given CompletableSubscriber to this Completable instance.final <T> void
unsafeSubscribe
(Subscriber<T> s) Subscribes a regular Subscriber to this Completable instance which will receive only an onError or onComplete event.private final <T> void
unsafeSubscribe
(Subscriber<T> s, boolean callOnStart) Performs the actual unsafe subscription and calls the onStart if required.final Completable
unsubscribeOn
(Scheduler scheduler) Returns a Completable which makes sure when a subscriber cancels the subscription, the dispose is called on the specified schedulerstatic <R> Completable
using
(Func0<R> resourceFunc0, Func1<? super R, ? extends Completable> completableFunc1, Action1<? 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
(Func0<R> resourceFunc0, Func1<? super R, ? extends Completable> completableFunc1, Action1<? 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.
-
Field Details
-
onSubscribe
The actual subscription action. -
COMPLETE
Single instance of a complete Completable. -
NEVER
Single instance of a never Completable.
-
-
Constructor Details
-
Completable
Constructs a Completable instance with the given onSubscribe callback.- Parameters:
onSubscribe
- the callback that will receive CompletableSubscribers when they subscribe, not null (not verified)
-
Completable
Constructs a Completable instance with the given onSubscribe callback without calling the onCreate hook.- Parameters:
onSubscribe
- the callback that will receive CompletableSubscribers when they subscribe, not null (not verified)useHook
- if false, RxJavaHooks.onCreate won't be called
-
-
Method Details
-
amb
Returns a Completable which terminates as soon as one of the source Completables terminates (normally or with an error) and cancels all other Completables.- Parameters:
sources
- the array of source Completables- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if sources is null
-
amb
Returns a Completable which terminates as soon as one of the source Completables terminates (normally or with an error) and cancels all other Completables.- Parameters:
sources
- the array of source Completables- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if sources is null
-
complete
Returns a Completable instance that completes immediately when subscribed to.- Returns:
- a Completable instance that completes immediately
-
concat
Returns a Completable which completes only when all sources complete, one after another.- Parameters:
sources
- the sources to concatenate- Returns:
- the Completable instance which completes only when all sources complete
- Throws:
NullPointerException
- if sources is null
-
concat
Returns a Completable which completes only when all sources complete, one after another.- Parameters:
sources
- the sources to concatenate- Returns:
- the Completable instance which completes only when all sources complete
- Throws:
NullPointerException
- if sources is null
-
concat
Returns a Completable which completes only when all sources complete, one after another.- Parameters:
sources
- the sources to concatenate- Returns:
- the Completable instance which completes only when all sources complete
- Throws:
NullPointerException
- if sources is null
-
concat
Returns a Completable which completes only when all sources complete, one after another.- Parameters:
sources
- the sources to concatenateprefetch
- the number of sources to prefetch from the sources- Returns:
- the Completable instance which completes only when all sources complete
- Throws:
NullPointerException
- if sources is null
-
create
Constructs a Completable instance by wrapping the given onSubscribe callback.- Parameters:
onSubscribe
- the callback which will receive the CompletableSubscriber instances when the Completable is subscribed to.- Returns:
- the created Completable instance
- Throws:
NullPointerException
- if onSubscribe is null
-
defer
Defers the subscription to a Completable instance returned by a supplier.- Parameters:
completableFunc0
- the supplier that returns the Completable that will be subscribed to.- Returns:
- the Completable instance
-
error
Creates a Completable which calls the given error supplier for each subscriber and emits its returned Throwable.If the errorFunc0 returns null, the child CompletableSubscribers will receive a NullPointerException.
- Parameters:
errorFunc0
- the error supplier, not null- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if errorFunc0 is null
-
error
Creates a Completable instance that emits the given Throwable exception to subscribers.- Parameters:
error
- the Throwable instance to emit, not null- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if error is null
-
fromAction
Returns a Completable instance that runs the given Action0 for each subscriber and emits either an unchecked exception or simply completes.- Parameters:
action
- the Action0 to run for each subscriber- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if run is null
-
fromCallable
Returns a Completable which when subscribed, executes the callable function, ignores its normal result and emits onError or onCompleted only.- Parameters:
callable
- the callable instance to execute for each subscriber- Returns:
- the new Completable instance
-
fromFuture
Returns a Completable instance that reacts to the termination of the given Future in a blocking fashion.Note that cancellation from any of the subscribers to this Completable will cancel the future.
- Parameters:
future
- the future to react to- Returns:
- the new Completable instance
-
fromObservable
Returns a Completable instance that subscribes to the given flowable, ignores all values and emits only the terminal event.- Parameters:
flowable
- the Flowable instance to subscribe to, not null- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if flowable is null
-
fromSingle
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.- Parameters:
single
- the Single instance to subscribe to, not null- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if single is null
-
merge
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.- Parameters:
sources
- the iterable sequence of sources.- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if sources is null
-
merge
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.- Parameters:
sources
- the iterable sequence of sources.- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if sources is null
-
merge
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.- Parameters:
sources
- the iterable sequence of sources.- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if sources is null
-
merge
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.- Parameters:
sources
- the iterable sequence of sources.maxConcurrency
- the maximum number of concurrent subscriptions- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if sources is nullIllegalArgumentException
- if maxConcurrency is less than 1
-
merge0
protected static Completable merge0(Observable<? extends Completable> sources, int maxConcurrency, boolean 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.- Parameters:
sources
- the iterable sequence of sources.maxConcurrency
- the maximum number of concurrent subscriptionsdelayErrors
- delay all errors from the main source and from the inner Completables?- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if sources is nullIllegalArgumentException
- if maxConcurrency is less than 1
-
mergeDelayError
Returns a Completable 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.- Parameters:
sources
- the array of Completables- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if sources is null
-
mergeDelayError
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.- Parameters:
sources
- the sequence of Completables- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if sources is null
-
mergeDelayError
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.- Parameters:
sources
- the sequence of Completables- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if sources is null
-
mergeDelayError
public static Completable mergeDelayError(Observable<? extends Completable> 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.- Parameters:
sources
- the sequence of CompletablesmaxConcurrency
- the maximum number of simultaneous subscriptions to the source Completables.- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if sources is null
-
never
Returns a Completable that never calls onError or onComplete.- Returns:
- the singleton instance that never calls onError or onComplete
-
requireNonNull
static <T> T requireNonNull(T o) Java 7 backport: throws a NullPointerException if o is null.- Parameters:
o
- the object to check- Returns:
- the o value
- Throws:
NullPointerException
- if o is null
-
timer
Returns a Completable instance that fires its onComplete event after the given delay elapsed.- Parameters:
delay
- the delay timeunit
- the delay unit- Returns:
- the new Completable instance
-
timer
Returns a Completable instance that fires its onCompleted event after the given delay elapsed by using the supplied scheduler.- Parameters:
delay
- the delay timeunit
- the delay unitscheduler
- the scheduler to use to emit the onCompleted event- Returns:
- the new Completable instance
-
toNpe
Creates a NullPointerException instance and sets the given Throwable as its initial cause.- Parameters:
ex
- the Throwable instance to use as cause, not null (not verified)- Returns:
- the created NullPointerException
-
using
public static <R> Completable using(Func0<R> resourceFunc0, Func1<? super R, ? extends Completable> completableFunc1, Action1<? super R> disposer) Returns a Completable instance which manages a resource along with a custom Completable instance while the subscription is active.This overload performs an eager unsubscription before the terminal event is emitted.
- Type Parameters:
R
- the resource type- Parameters:
resourceFunc0
- the supplier that returns a resource to be managed.completableFunc1
- 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- Returns:
- the new Completable instance
-
using
public static <R> Completable using(Func0<R> resourceFunc0, Func1<? super R, ? extends Completable> completableFunc1, Action1<? 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.If this overload performs a lazy unsubscription after the terminal event is emitted. Exceptions thrown at this time will be delivered to RxJavaPlugins only.
- Type Parameters:
R
- the resource type- Parameters:
resourceFunc0
- the supplier that returns a resource to be managedcompletableFunc1
- 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- Returns:
- the new Completable instance
-
ambWith
Returns a Completable that emits the a terminated event of either this Completable or the other Completable whichever fires first.- Parameters:
other
- the other Completable, not null- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if other is null
-
await
public final void await()Subscribes to and awaits the termination of this Completable instance in a blocking manner and rethrows any exception emitted.- Throws:
RuntimeException
- wrapping an InterruptedException if the current thread is interrupted
-
await
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.- Parameters:
timeout
- the timeout valueunit
- the timeout unit- Returns:
- true if the this Completable instance completed normally within the time limit, false if the timeout elapsed before this Completable terminated.
- Throws:
RuntimeException
- wrapping an InterruptedException if the current thread is interrupted
-
compose
Calls the given transformer function with this instance and returns the function's resulting Completable.- Parameters:
transformer
- the transformer function, not null- Returns:
- the Completable returned by the function
- Throws:
NullPointerException
- if transformer is null
-
andThen
Returns an Observable which will subscribe to this Completable and once that is completed then will subscribe to thenext
Observable. An error event from this Completable will be propagated to the downstream subscriber and will result in skipping the subscription of the Observable.- Type Parameters:
T
- the value type of the next Observable- Parameters:
next
- the Observable to subscribe after this Completable is completed, not null- Returns:
- Observable that composes this Completable and next
- Throws:
NullPointerException
- if next is null
-
andThen
Returns a Single which will subscribe to this Completable and once that is completed then will subscribe to thenext
Single. An error event from this Completable will be propagated to the downstream subscriber and will result in skipping the subscription of the Single.- Scheduler:
andThen
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type of the next Single- Parameters:
next
- the Single to subscribe after this Completable is completed, not null- Returns:
- Single that composes this Completable and next
-
andThen
Returns a completable that first runs this Completable and then the other completable.This is an alias for
concatWith(Completable)
.- Parameters:
next
- the other Completable, not null- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if other is null
-
concatWith
Concatenates this Completable with another Completable.- Parameters:
other
- the other Completable, not null- Returns:
- the new Completable which subscribes to this and then the other Completable
- Throws:
NullPointerException
- if other is null
-
delay
Returns a Completable which delays the emission of the completion event by the given time.- Parameters:
delay
- the delay timeunit
- the delay unit- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if unit is null
-
delay
Returns a Completable which delays the emission of the completion event by the given time while running on the specified scheduler.- Parameters:
delay
- the delay timeunit
- the delay unitscheduler
- the scheduler to run the delayed completion on- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if unit or scheduler is null
-
delay
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.- Parameters:
delay
- the delay timeunit
- the delay unitscheduler
- the scheduler to run the delayed completion ondelayError
- delay the error emission as well?- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if unit or scheduler is null
-
doOnComplete
Deprecated.UsedoOnCompleted(Action0)
instead.Returns a Completable which calls the given onComplete callback if this Completable completes.- Parameters:
onComplete
- the callback to call when this emits an onComplete event- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if onComplete is null
-
doOnCompleted
Returns a Completable which calls the given onCompleted callback if this Completable completes.- Parameters:
onCompleted
- the callback to call when this emits an onComplete event- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if onComplete is null
-
doOnUnsubscribe
Returns a Completable which calls the given onUnsubscribe callback if the child subscriber cancels the subscription.- Parameters:
onUnsubscribe
- the callback to call when the child subscriber cancels the subscription- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if onDispose is null
-
doOnError
Returns a Completable which calls the given onError callback if this Completable emits an error.- Parameters:
onError
- the error callback- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if onError is null
-
doOnLifecycle
protected final Completable doOnLifecycle(Action1<? super Subscription> onSubscribe, Action1<? super Throwable> onError, Action0 onComplete, Action0 onAfterComplete, Action0 onUnsubscribe) Returns a Completable instance that calls the various callbacks on the specific lifecycle events.- Parameters:
onSubscribe
- the consumer called when a CompletableSubscriber subscribes.onError
- the consumer called when this emits an onError eventonComplete
- the runnable called just before when this Completable completes normallyonAfterComplete
- the runnable called after this Completable completes normallyonUnsubscribe
- the runnable called when the child cancels the subscription- Returns:
- the new Completable instance
-
doOnSubscribe
Returns a Completable instance that calls the given onSubscribe callback with the disposable that child subscribers receive on subscription.- Parameters:
onSubscribe
- the callback called when a child subscriber subscribes- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if onSubscribe is null
-
doOnTerminate
Returns a Completable instance that calls the given onTerminate callback just before this Completable completes normally or with an exception- Parameters:
onTerminate
- the callback to call just before this Completable terminates- Returns:
- the new Completable instance
-
endWith
Deprecated.UseandThen(rx.Completable)
instead.Returns a completable that first runs this Completable and then the other completable.This is an alias for
concatWith(Completable)
.- Parameters:
other
- the other Completable, not null- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if other is null
-
endWith
Deprecated.UseandThen(rx.Observable)
instead.Returns an Observable that first runs this Completable instance and resumes with the given next Observable.- Type Parameters:
T
- the value type of the next Observable- Parameters:
next
- the next Observable to continue- Returns:
- the new Observable instance
-
doAfterTerminate
Returns a Completable instance that calls the given onAfterComplete callback after this Completable completes normally.- Parameters:
onAfterComplete
- the callback to call after this Completable emits an onComplete event.- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if onAfterComplete is null
-
get
Subscribes to this Completable instance and blocks until it terminates, then returns null or the emitted exception if any.- Returns:
- the throwable if this terminated with an error, null otherwise
- Throws:
RuntimeException
- that wraps an InterruptedException if the wait is interrupted
-
get
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.- Parameters:
timeout
- the time amount to wait for the terminal eventunit
- the time unit of the timeout parameter- Returns:
- the throwable if this terminated with an error, null otherwise
- Throws:
RuntimeException
- that wraps an InterruptedException if the wait is interrupted or TimeoutException if the specified timeout elapsed before it
-
lift
Lifts a CompletableSubscriber transformation into the chain of Completables.- Parameters:
onLift
- the lifting function that transforms the child subscriber with a parent subscriber.- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if onLift is null
-
mergeWith
Returns a Completable which subscribes to this and the other Completable and completes when both of them complete or one emits an error.- Parameters:
other
- the other Completable instance- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if other is null
-
observeOn
Returns a Completable which emits the terminal events from the thread of the specified scheduler.- Parameters:
scheduler
- the scheduler to emit terminal events on- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if scheduler is null
-
onErrorComplete
Returns a Completable instance that if this Completable emits an error, it will emit an onComplete and swallow the throwable.- Returns:
- the new Completable instance
-
onErrorComplete
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.- Parameters:
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.- Returns:
- the new Completable instance
-
onErrorResumeNext
public final Completable onErrorResumeNext(Func1<? super Throwable, ? extends Completable> 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.- Parameters:
errorMapper
- the mapper function that takes the error and should return a Completable as continuation.- Returns:
- the new Completable instance
-
repeat
Returns a Completable that repeatedly subscribes to this Completable until cancelled.- Returns:
- the new Completable instance
-
repeat
Returns a Completable that subscribes repeatedly at most the given times to this Completable.- Parameters:
times
- the number of times the resubscription should happen- Returns:
- the new Completable instance
- Throws:
IllegalArgumentException
- if times is less than zero
-
repeatWhen
public final Completable repeatWhen(Func1<? super Observable<? extends Void>, ? extends Observable<?>> 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.- Parameters:
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 stop- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if stop is null
-
retry
Returns a Completable that retries this Completable as long as it emits an onError event.- Returns:
- the new Completable instance
-
retry
Returns a Completable that retries this Completable in case of an error as long as the predicate returns true.- Parameters:
predicate
- the predicate called when this emits an error with the repeat count and the latest exception and should return true to retry.- Returns:
- the new Completable instance
-
retry
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.- Parameters:
times
- the number of times the returned Completable should retry this Completable- Returns:
- the new Completable instance
- Throws:
IllegalArgumentException
- if times is negative
-
retryWhen
public final Completable retryWhen(Func1<? super Observable<? extends Throwable>, ? extends Observable<?>> handler) Returns a Completable which given a Publisher and when this Completable emits an error, delivers that error through an Observable and the Publisher should return a value indicating a retry in response or a terminal event indicating a termination.- Parameters:
handler
- the handler that receives an Observable delivering Throwables and should return a Publisher that emits items to indicate retries or emits terminal events to indicate termination.- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if handler is null
-
startWith
Returns a Completable which first runs the other Completable then this completable if the other completed normally.- Parameters:
other
- the other completable to run first- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if other is null
-
startWith
Returns an Observable which first delivers the events of the other Observable then runs this Completable.- Type Parameters:
T
- the value type of the starting other Observable- Parameters:
other
- the other Observable to run first- Returns:
- the new Observable instance
- Throws:
NullPointerException
- if other is null
-
subscribe
Subscribes to this Completable and returns a Subscription which can be used to cancel the subscription.- Returns:
- the Subscription that allows cancelling the subscription
-
subscribe
Subscribes to this Completable and calls the given Action0 when this Completable completes normally.If this Completable emits an error, it is sent to RxJavaHooks.onError and gets swallowed.
- Parameters:
onComplete
- the runnable called when this Completable completes normally- Returns:
- the Subscription that allows cancelling the subscription
-
subscribe
Subscribes to this Completable and calls back either the onError or onComplete functions.- Parameters:
onComplete
- the runnable that is called if the Completable completes normallyonError
- the consumer that is called if this Completable emits an error- Returns:
- the Subscription that can be used for cancelling the subscription asynchronously
- Throws:
NullPointerException
- if either callback is null
-
deliverUncaughtException
-
unsafeSubscribe
Subscribes the given CompletableSubscriber to this Completable instance.- Parameters:
s
- the CompletableSubscriber, not null- Throws:
NullPointerException
- if s is null
-
subscribe
Subscribes the given CompletableSubscriber to this Completable instance and handles exceptions thrown by its onXXX methods.- Parameters:
s
- the CompletableSubscriber, not null- Throws:
NullPointerException
- if s is null
-
unsafeSubscribe
Subscribes a regular Subscriber to this Completable instance which will receive only an onError or onComplete event.- Type Parameters:
T
- the value type of the subscriber- Parameters:
s
- the reactive-streams Subscriber, not null- Throws:
NullPointerException
- if s is null
-
unsafeSubscribe
Performs the actual unsafe subscription and calls the onStart if required.- Type Parameters:
T
- the value type of the subscriber- Parameters:
s
- the subscriber instance, not nullcallOnStart
- if true, the Subscriber.onStart will be called- Throws:
NullPointerException
- if s is null
-
subscribe
Subscribes a regular Subscriber to this Completable instance which will receive only an onError or onComplete event and handles exceptions thrown by its onXXX methods.- Type Parameters:
T
- the value type of the subscriber- Parameters:
s
- the reactive-streams Subscriber, not null- Throws:
NullPointerException
- if s is null
-
subscribeOn
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.- Parameters:
scheduler
- the Scheduler to subscribe on- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if scheduler is null
-
timeout
Returns a Completable that runs this Completable and emits a TimeoutException in case this Completable doesn't complete within the given time.- Parameters:
timeout
- the timeout valueunit
- the timeout unit- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if unit is null
-
timeout
Returns a Completable that runs this Completable and switches to the other Completable in case this Completable doesn't complete within the given time.- Parameters:
timeout
- the timeout valueunit
- the timeout unitother
- the other Completable instance to switch to in case of a timeout- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if unit or other is null
-
timeout
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.- Parameters:
timeout
- the timeout valueunit
- the timeout unitscheduler
- the scheduler to use to wait for completion- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if unit or scheduler is null
-
timeout
public final Completable timeout(long timeout, TimeUnit unit, Scheduler scheduler, Completable 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.- Parameters:
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 timeout- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if unit, scheduler or other is null
-
timeout0
public final Completable timeout0(long timeout, TimeUnit unit, Scheduler scheduler, Completable 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.- Parameters:
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 timeout, if null a TimeoutException is emitted instead- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if unit or scheduler
-
to
Allows fluent conversion to another type via a function callback.- Type Parameters:
U
- the output type as determined by the converter function- Parameters:
converter
- the function called with this which should return some other value.- Returns:
- the converted value
- Throws:
NullPointerException
- if converter is null
-
toObservable
Returns an Observable which when subscribed to subscribes to this Completable and relays the terminal events to the subscriber.- Type Parameters:
T
- the target type of the Observable- Returns:
- the new Observable created
-
toSingle
Converts this Completable into a Single which when this Completable completes normally, calls the given supplier and emits its returned value through onSuccess.- Type Parameters:
T
- the value type of the resulting Single- Parameters:
completionValueFunc0
- the value supplier called when this Completable completes normally- Returns:
- the new Single instance
- Throws:
NullPointerException
- if completionValueFunc0 is null
-
toSingleDefault
Converts this Completable into a Single which when this Completable completes normally, emits the given value through onSuccess.- Type Parameters:
T
- the value type of the resulting Single- Parameters:
completionValue
- the value to emit when this Completable completes normally- Returns:
- the new Single instance
- Throws:
NullPointerException
- if completionValue is null
-
unsubscribeOn
Returns a Completable which makes sure when a subscriber cancels the subscription, the dispose is called on the specified scheduler- Parameters:
scheduler
- the target scheduler where to execute the cancellation- Returns:
- the new Completable instance
- Throws:
NullPointerException
- if scheduler is null
-
doOnCompleted(Action0)
instead.