Package rx
Class Completable
- java.lang.Object
-
- rx.Completable
-
@Experimental public class Completable extends java.lang.Object
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 Classes Modifier and Type Class Description static interface
Completable.CompletableOnSubscribe
Callback used for building deferred computations that takes a CompletableSubscriber.static interface
Completable.CompletableOperator
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
Completable.CompletableSubscriber
Represents the subscription API callbacks when subscribing to a Completable instance.static interface
Completable.CompletableTransformer
Convenience interface and callback used by the compose operator to turn a Completable into another Completable fluently.
-
Field Summary
Fields Modifier and Type Field Description (package private) static Completable
COMPLETE
Single instance of a complete Completable.(package private) static Completable
NEVER
Single instance of a never Completable.private Completable.CompletableOnSubscribe
onSubscribe
The actual subscription action.
-
Constructor Summary
Constructors Modifier Constructor Description protected
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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Completable
amb(java.lang.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.Completable
ambWith(Completable other)
Returns a Completable that emits the a terminated event of either this Completable or the other Completable whichever fires first.Completable
andThen(Completable next)
Returns a completable that first runs this Completable and then the other completable.<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.<T> Single<T>
andThen(Single<T> next)
Returns a Single which will subscribe to this Completable and once that is completed then will subscribe to thenext
Single.void
await()
Subscribes to and awaits the termination of this Completable instance in a blocking manner and rethrows any exception emitted.boolean
await(long timeout, java.util.concurrent.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.static Completable
complete()
Returns a Completable instance that completes immediately when subscribed to.Completable
compose(Completable.CompletableTransformer transformer)
Calls the given transformer function with this instance and returns the function's resulting Completable.static Completable
concat(java.lang.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.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.Completable
delay(long delay, java.util.concurrent.TimeUnit unit)
Returns a Completable which delays the emission of the completion event by the given time.Completable
delay(long delay, java.util.concurrent.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, java.util.concurrent.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.private static void
deliverUncaughtException(java.lang.Throwable e)
Completable
doAfterTerminate(Action0 onAfterComplete)
Returns a Completable instance that calls the given onAfterComplete callback after this Completable completes normally.Completable
doOnComplete(Action0 onComplete)
Deprecated.UsedoOnCompleted(Action0)
instead.Completable
doOnCompleted(Action0 onCompleted)
Returns a Completable which calls the given onCompleted callback if this Completable completes.Completable
doOnError(Action1<? super java.lang.Throwable> onError)
Returns a Completable which calls the given onError callback if this Completable emits an error.protected Completable
doOnLifecycle(Action1<? super Subscription> onSubscribe, Action1<? super java.lang.Throwable> onError, Action0 onComplete, Action0 onAfterComplete, Action0 onUnsubscribe)
Returns a Completable instance that calls the various callbacks on the specific lifecycle events.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.Completable
doOnTerminate(Action0 onTerminate)
Returns a Completable instance that calls the given onTerminate callback just before this Completable completes normally or with an exceptionCompletable
doOnUnsubscribe(Action0 onUnsubscribe)
Returns a Completable which calls the given onUnsubscribe callback if the child subscriber cancels the subscription.Completable
endWith(Completable other)
Deprecated.UseandThen(rx.Completable)
instead.<T> Observable<T>
endWith(Observable<T> next)
Deprecated.UseandThen(rx.Observable)
instead.static Completable
error(java.lang.Throwable error)
Creates a Completable instance that emits the given Throwable exception to subscribers.static Completable
error(Func0<? extends java.lang.Throwable> errorFunc0)
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(java.util.concurrent.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(java.util.concurrent.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.java.lang.Throwable
get()
Subscribes to this Completable instance and blocks until it terminates, then returns null or the emitted exception if any.java.lang.Throwable
get(long timeout, java.util.concurrent.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
lift(Completable.CompletableOperator onLift)
Lifts a CompletableSubscriber transformation into the chain of Completables.static Completable
merge(java.lang.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(java.lang.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.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.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(Func1<? super java.lang.Throwable,java.lang.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.Completable
onErrorResumeNext(Func1<? super java.lang.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.Completable
repeat()
Returns a Completable that repeatedly subscribes to this Completable until cancelled.Completable
repeat(long times)
Returns a Completable that subscribes repeatedly at most the given times to this Completable.Completable
repeatWhen(Func1<? super Observable<? extends java.lang.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.Completable
retry()
Returns a Completable that retries this Completable as long as it emits an onError event.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(Func2<java.lang.Integer,java.lang.Throwable,java.lang.Boolean> predicate)
Returns a Completable that retries this Completable in case of an error as long as the predicate returns true.Completable
retryWhen(Func1<? super Observable<? extends java.lang.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.Completable
startWith(Completable 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 Completable.Subscription
subscribe()
Subscribes to this Completable and returns a Subscription which can be used to cancel the subscription.void
subscribe(Completable.CompletableSubscriber s)
Subscribes the given CompletableSubscriber to this Completable instance and handles exceptions thrown by its onXXX methods.Subscription
subscribe(Action0 onComplete)
Subscribes to this Completable and calls the given Action0 when this Completable completes normally.Subscription
subscribe(Action0 onComplete, Action1<? super java.lang.Throwable> onError)
Subscribes to this Completable and calls back either the onError or onComplete functions.<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.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.Completable
timeout(long timeout, java.util.concurrent.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, java.util.concurrent.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.Completable
timeout(long timeout, java.util.concurrent.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, java.util.concurrent.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.Completable
timeout0(long timeout, java.util.concurrent.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
timer(long delay, java.util.concurrent.TimeUnit unit)
Returns a Completable instance that fires its onComplete event after the given delay elapsed.static Completable
timer(long delay, java.util.concurrent.TimeUnit unit, Scheduler scheduler)
Returns a Completable instance that fires its onCompleted event after the given delay elapsed by using the supplied scheduler.<U> U
to(Func1<? super Completable,U> converter)
Allows fluent conversion to another type via a function callback.(package private) static java.lang.NullPointerException
toNpe(java.lang.Throwable ex)
Creates a NullPointerException instance and sets the given Throwable as its initial cause.<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(Func0<? extends T> completionValueFunc0)
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.void
unsafeSubscribe(Completable.CompletableSubscriber s)
Subscribes the given CompletableSubscriber to this Completable instance.<T> void
unsafeSubscribe(Subscriber<T> s)
Subscribes a regular Subscriber to this Completable instance which will receive only an onError or onComplete event.private <T> void
unsafeSubscribe(Subscriber<T> s, boolean callOnStart)
Performs the actual unsafe subscription and calls the onStart if required.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 Detail
-
onSubscribe
private final Completable.CompletableOnSubscribe onSubscribe
The actual subscription action.
-
COMPLETE
static final Completable COMPLETE
Single instance of a complete Completable.
-
NEVER
static final Completable NEVER
Single instance of a never Completable.
-
-
Constructor Detail
-
Completable
protected Completable(Completable.CompletableOnSubscribe onSubscribe)
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
private Completable(Completable.CompletableOnSubscribe onSubscribe, boolean useHook)
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 Detail
-
amb
public 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.- Parameters:
sources
- the array of source Completables- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if sources is null
-
amb
public static Completable amb(java.lang.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.- Parameters:
sources
- the array of source Completables- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if sources is null
-
complete
public static Completable complete()
Returns a Completable instance that completes immediately when subscribed to.- Returns:
- a Completable instance that completes immediately
-
concat
public static Completable concat(Completable... sources)
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:
java.lang.NullPointerException
- if sources is null
-
concat
public static Completable concat(java.lang.Iterable<? extends Completable> sources)
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:
java.lang.NullPointerException
- if sources is null
-
concat
public static Completable concat(Observable<? extends Completable> sources)
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:
java.lang.NullPointerException
- if sources is null
-
concat
public static Completable concat(Observable<? extends Completable> sources, int prefetch)
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:
java.lang.NullPointerException
- if sources is null
-
create
public static Completable create(Completable.CompletableOnSubscribe onSubscribe)
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:
java.lang.NullPointerException
- if onSubscribe is null
-
defer
public static Completable defer(Func0<? extends Completable> completableFunc0)
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
public static Completable error(Func0<? extends java.lang.Throwable> errorFunc0)
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:
java.lang.NullPointerException
- if errorFunc0 is null
-
error
public static Completable error(java.lang.Throwable 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:
java.lang.NullPointerException
- if error is null
-
fromAction
public 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.- Parameters:
action
- the Action0 to run for each subscriber- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if run is null
-
fromCallable
public static Completable fromCallable(java.util.concurrent.Callable<?> callable)
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
public static Completable fromFuture(java.util.concurrent.Future<?> future)
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
public static Completable fromObservable(Observable<?> flowable)
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:
java.lang.NullPointerException
- if flowable is null
-
fromSingle
public 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.- Parameters:
single
- the Single instance to subscribe to, not null- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if single is null
-
merge
public 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.- Parameters:
sources
- the iterable sequence of sources.- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if sources is null
-
merge
public static Completable merge(java.lang.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.- Parameters:
sources
- the iterable sequence of sources.- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if sources is null
-
merge
public 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.- Parameters:
sources
- the iterable sequence of sources.- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if sources is null
-
merge
public 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.- Parameters:
sources
- the iterable sequence of sources.maxConcurrency
- the maximum number of concurrent subscriptions- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if sources is nulljava.lang.IllegalArgumentException
- 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:
java.lang.NullPointerException
- if sources is nulljava.lang.IllegalArgumentException
- if maxConcurrency is less than 1
-
mergeDelayError
public 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.- Parameters:
sources
- the array of Completables- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if sources is null
-
mergeDelayError
public static Completable mergeDelayError(java.lang.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.- Parameters:
sources
- the sequence of Completables- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if sources is null
-
mergeDelayError
public 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.- Parameters:
sources
- the sequence of Completables- Returns:
- the new Completable instance
- Throws:
java.lang.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:
java.lang.NullPointerException
- if sources is null
-
never
public static Completable 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:
java.lang.NullPointerException
- if o is null
-
timer
public static Completable timer(long delay, java.util.concurrent.TimeUnit unit)
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
public static Completable timer(long delay, java.util.concurrent.TimeUnit unit, Scheduler scheduler)
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
static java.lang.NullPointerException toNpe(java.lang.Throwable ex)
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
public 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.- Parameters:
other
- the other Completable, not null- Returns:
- the new Completable instance
- Throws:
java.lang.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:
java.lang.RuntimeException
- wrapping an InterruptedException if the current thread is interrupted
-
await
public final boolean await(long timeout, java.util.concurrent.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.- 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:
java.lang.RuntimeException
- wrapping an InterruptedException if the current thread is interrupted
-
compose
public final Completable compose(Completable.CompletableTransformer transformer)
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:
java.lang.NullPointerException
- if transformer is null
-
andThen
public 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. 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:
java.lang.NullPointerException
- if next is null
-
andThen
public final <T> Single<T> andThen(Single<T> next)
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
public final Completable andThen(Completable next)
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:
java.lang.NullPointerException
- if other is null
-
concatWith
public final Completable concatWith(Completable other)
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:
java.lang.NullPointerException
- if other is null
-
delay
public final Completable delay(long delay, java.util.concurrent.TimeUnit unit)
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:
java.lang.NullPointerException
- if unit is null
-
delay
public final Completable delay(long delay, java.util.concurrent.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.- Parameters:
delay
- the delay timeunit
- the delay unitscheduler
- the scheduler to run the delayed completion on- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if unit or scheduler is null
-
delay
public final Completable delay(long delay, java.util.concurrent.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.- 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:
java.lang.NullPointerException
- if unit or scheduler is null
-
doOnComplete
@Deprecated public final Completable doOnComplete(Action0 onComplete)
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:
java.lang.NullPointerException
- if onComplete is null
-
doOnCompleted
public final Completable doOnCompleted(Action0 onCompleted)
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:
java.lang.NullPointerException
- if onComplete is null
-
doOnUnsubscribe
public final Completable doOnUnsubscribe(Action0 onUnsubscribe)
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:
java.lang.NullPointerException
- if onDispose is null
-
doOnError
public final Completable doOnError(Action1<? super java.lang.Throwable> onError)
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:
java.lang.NullPointerException
- if onError is null
-
doOnLifecycle
protected final Completable doOnLifecycle(Action1<? super Subscription> onSubscribe, Action1<? super java.lang.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
public 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.- Parameters:
onSubscribe
- the callback called when a child subscriber subscribes- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if onSubscribe is null
-
doOnTerminate
public final Completable doOnTerminate(Action0 onTerminate)
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 public final Completable endWith(Completable other)
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:
java.lang.NullPointerException
- if other is null
-
endWith
@Deprecated public final <T> Observable<T> endWith(Observable<T> next)
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
public final Completable doAfterTerminate(Action0 onAfterComplete)
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:
java.lang.NullPointerException
- if onAfterComplete is null
-
get
public final java.lang.Throwable 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:
java.lang.RuntimeException
- that wraps an InterruptedException if the wait is interrupted
-
get
public final java.lang.Throwable get(long timeout, java.util.concurrent.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.- 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:
java.lang.RuntimeException
- that wraps an InterruptedException if the wait is interrupted or TimeoutException if the specified timeout elapsed before it
-
lift
public final Completable lift(Completable.CompletableOperator onLift)
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:
java.lang.NullPointerException
- if onLift is null
-
mergeWith
public 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.- Parameters:
other
- the other Completable instance- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if other is null
-
observeOn
public final Completable observeOn(Scheduler scheduler)
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:
java.lang.NullPointerException
- if scheduler is null
-
onErrorComplete
public final Completable 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
public final Completable onErrorComplete(Func1<? super java.lang.Throwable,java.lang.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.- 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 java.lang.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
public final Completable repeat()
Returns a Completable that repeatedly subscribes to this Completable until cancelled.- Returns:
- the new Completable instance
-
repeat
public final Completable repeat(long times)
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:
java.lang.IllegalArgumentException
- if times is less than zero
-
repeatWhen
public final Completable repeatWhen(Func1<? super Observable<? extends java.lang.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:
java.lang.NullPointerException
- if stop is null
-
retry
public final Completable retry()
Returns a Completable that retries this Completable as long as it emits an onError event.- Returns:
- the new Completable instance
-
retry
public final Completable retry(Func2<java.lang.Integer,java.lang.Throwable,java.lang.Boolean> predicate)
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
public 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.- Parameters:
times
- the number of times the returned Completable should retry this Completable- Returns:
- the new Completable instance
- Throws:
java.lang.IllegalArgumentException
- if times is negative
-
retryWhen
public final Completable retryWhen(Func1<? super Observable<? extends java.lang.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:
java.lang.NullPointerException
- if handler is null
-
startWith
public final Completable startWith(Completable other)
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:
java.lang.NullPointerException
- if other is null
-
startWith
public final <T> Observable<T> startWith(Observable<T> other)
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:
java.lang.NullPointerException
- if other is null
-
subscribe
public final Subscription 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
public final Subscription subscribe(Action0 onComplete)
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
public final Subscription subscribe(Action0 onComplete, Action1<? super java.lang.Throwable> onError)
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:
java.lang.NullPointerException
- if either callback is null
-
deliverUncaughtException
private static void deliverUncaughtException(java.lang.Throwable e)
-
unsafeSubscribe
public final void unsafeSubscribe(Completable.CompletableSubscriber s)
Subscribes the given CompletableSubscriber to this Completable instance.- Parameters:
s
- the CompletableSubscriber, not null- Throws:
java.lang.NullPointerException
- if s is null
-
subscribe
public final void subscribe(Completable.CompletableSubscriber s)
Subscribes the given CompletableSubscriber to this Completable instance and handles exceptions thrown by its onXXX methods.- Parameters:
s
- the CompletableSubscriber, not null- Throws:
java.lang.NullPointerException
- if s is null
-
unsafeSubscribe
public final <T> void unsafeSubscribe(Subscriber<T> s)
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:
java.lang.NullPointerException
- if s is null
-
unsafeSubscribe
private final <T> void unsafeSubscribe(Subscriber<T> s, boolean callOnStart)
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:
java.lang.NullPointerException
- if s is null
-
subscribe
public 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.- Type Parameters:
T
- the value type of the subscriber- Parameters:
s
- the reactive-streams Subscriber, not null- Throws:
java.lang.NullPointerException
- if s is null
-
subscribeOn
public 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.- Parameters:
scheduler
- the Scheduler to subscribe on- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if scheduler is null
-
timeout
public final Completable timeout(long timeout, java.util.concurrent.TimeUnit unit)
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:
java.lang.NullPointerException
- if unit is null
-
timeout
public final Completable timeout(long timeout, java.util.concurrent.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.- 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:
java.lang.NullPointerException
- if unit or other is null
-
timeout
public final Completable timeout(long timeout, java.util.concurrent.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.- Parameters:
timeout
- the timeout valueunit
- the timeout unitscheduler
- the scheduler to use to wait for completion- Returns:
- the new Completable instance
- Throws:
java.lang.NullPointerException
- if unit or scheduler is null
-
timeout
public final Completable timeout(long timeout, java.util.concurrent.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:
java.lang.NullPointerException
- if unit, scheduler or other is null
-
timeout0
public final Completable timeout0(long timeout, java.util.concurrent.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:
java.lang.NullPointerException
- if unit or scheduler
-
to
public final <U> U to(Func1<? super Completable,U> converter)
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:
java.lang.NullPointerException
- if converter is null
-
toObservable
public final <T> Observable<T> 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
public final <T> Single<T> toSingle(Func0<? extends T> completionValueFunc0)
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:
java.lang.NullPointerException
- if completionValueFunc0 is null
-
toSingleDefault
public 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.- 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:
java.lang.NullPointerException
- if completionValue is null
-
unsubscribeOn
public final Completable unsubscribeOn(Scheduler scheduler)
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:
java.lang.NullPointerException
- if scheduler is null
-
-