Top Description Inners Fields Constructors Methods
rx

public Class Completable

extends Object
Class Inheritance
Imports
java.util.*, java.util.concurrent.*, java.util.concurrent.atomic.AtomicBoolean, rx.exceptions.*, rx.functions.*, rx.internal.observers.AssertableSubscriberObservable, rx.internal.operators.*, rx.internal.util.*, rx.observers.*, rx.plugins.RxJavaHooks, rx.schedulers.Schedulers, rx.subscriptions.*

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)?
Since
1.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Completable.OnSubscribe

Callback used for building deferred computations that takes a CompletableSubscriber.

public static interface
Completable.Operator

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.

public static interface
Completable.Transformer

Convenience interface and callback used by the compose operator to turn a Completable into another Completable fluently.

Field Summary

Modifier and TypeField and Description
pack-priv static final Completable
COMPLETE

Single instance of a complete Completable.

pack-priv static final Completable
NEVER

Single instance of a never Completable.

private final Completable.OnSubscribe
onSubscribe

The actual subscription action.

Constructor Summary

AccessConstructor and Description
protected
Completable(Completable.OnSubscribe
the callback that will receive CompletableSubscribers when they subscribe, not null (not verified)
onSubscribe
)

Constructs a Completable instance with the given onSubscribe callback.

protected
Completable(Completable.OnSubscribe
the callback that will receive CompletableSubscribers when they subscribe, not null (not verified)
onSubscribe
,
boolean
if false, RxJavaHooks.onCreate won't be called
useHook
)

Constructs a Completable instance with the given onSubscribe callback without calling the onCreate hook.

Method Summary

Modifier and TypeMethod and Description
public static Completable

Returns:

the new Completable instance
amb
(final Completable...
the array of source Completables
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.

public static Completable

Returns:

the new Completable instance
amb
(final Iterable<? extends Completable>
the array of source Completables
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.

public final Completable

Returns:

the new Completable instance
ambWith
(Completable
the other Completable, not null
other
)

Returns a Completable that emits the a terminated event of either this Completable or the other Completable whichever fires first.

public final <
the value type of the next Observable
T
>
Observable<T>

Returns:

Observable that composes this Completable and next
andThen
(Observable<T>
the Observable to subscribe after this Completable is completed, not null
next
)

Returns an Observable which will subscribe to this Completable and once that is completed then will subscribe to the next Observable.

public final <
the value type of the next Single
T
>
Single<T>

Returns:

Single that composes this Completable and next
andThen
(Single<T>
the Single to subscribe after this Completable is completed, not null
next
)

Returns a Single which will subscribe to this Completable and once that is completed then will subscribe to the next Single.

public final Completable

Returns:

the new Completable instance
andThen
(Completable
the other Completable, not null
next
)

Returns a completable that first runs this Completable and then the other completable.

public final void
await()

Subscribes to and awaits the termination of this Completable instance in a blocking manner and rethrows any exception emitted.

public final boolean

Returns:

true if the this Completable instance completed normally within the time limit, false if the timeout elapsed before this Completable terminated.
await
(long
the timeout value
timeout
,
TimeUnit
the timeout unit
unit
)

Subscribes to and awaits the termination of this Completable instance in a blocking manner with a specific timeout and rethrows any exception emitted within the timeout window.

public static Completable

Returns:

a Completable instance that completes immediately
complete
()

Returns a Completable instance that completes immediately when subscribed to.

public final Completable

Returns:

the Completable returned by the function
compose
(Completable.Transformer
the transformer function, not null
transformer
)

Calls the given transformer function with this instance and returns the function's resulting Completable.

public static Completable

Returns:

the Completable instance which completes only when all sources complete
concat
(Completable...
the sources to concatenate
sources
)

Returns a Completable which completes only when all sources complete, one after another.

public static Completable

Returns:

the Completable instance which completes only when all sources complete
concat
(Iterable<? extends Completable>
the sources to concatenate
sources
)

Returns a Completable which completes only when all sources complete, one after another.

public static Completable

Returns:

the Completable instance which completes only when all sources complete
concat
(Observable<? extends Completable>
the sources to concatenate
sources
)

Returns a Completable which completes only when all sources complete, one after another.

public static Completable

Returns:

the Completable instance which completes only when all sources complete
concat
(Observable<? extends Completable>
the sources to concatenate
sources
,
int
the number of sources to prefetch from the sources
prefetch
)

Returns a Completable which completes only when all sources complete, one after another.

public final Completable

Returns:

the new Completable which subscribes to this and then the other Completable
concatWith
(Completable
the other Completable, not null
other
)

Concatenates this Completable with another Completable.

public static Completable

Returns:

the created Completable instance
create
(Completable.OnSubscribe
the callback which will receive the CompletableSubscriber instances when the Completable is subscribed to.
onSubscribe
)

Constructs a Completable instance by wrapping the given onSubscribe callback.

public static Completable

Returns:

the Completable instance
defer
(final Func0<? extends Completable>
the supplier that returns the Completable that will be subscribed to.
completableFunc0
)

Defers the subscription to a Completable instance returned by a supplier.

public final Completable

Returns:

the new Completable instance
delay
(long
the delay time
delay
,
TimeUnit
the delay unit
unit
)

Returns a Completable which delays the emission of the completion event by the given time.

public final Completable

Returns:

the new Completable instance
delay
(long
the delay time
delay
,
TimeUnit
the delay unit
unit
,
Scheduler
the scheduler to run the delayed completion on
scheduler
)

Returns a Completable which delays the emission of the completion event by the given time while running on the specified scheduler.

public final Completable

Returns:

the new Completable instance
delay
(final long
the delay time
delay
,
final TimeUnit
the delay unit
unit
,
final Scheduler
the scheduler to run the delayed completion on
scheduler
,
final boolean
delay the error emission as well?
delayError
)

Returns a Completable which delays the emission of the completion event, and optionally the error as well, by the given time while running on the specified scheduler.

pack-priv static void
public final Completable

Returns:

the new Completable instance
doAfterTerminate
(Action0
the callback to call after this Completable emits an onCompleted or onError event.
onAfterTerminate
)

Returns a Completable instance that calls the given onAfterComplete callback after this Completable completes normally.

public final Completable

Returns:

the new Completable instance
doOnCompleted
(Action0
the callback to call when this emits an onComplete event
onCompleted
)

Returns a Completable which calls the given onCompleted callback if this Completable completes.

public final Completable

Returns:

the new Completable instance
doOnEach
(final Action1<Notification<Object>>
the notification callback
onNotification
)

Returns a Completable which calls the given onNotification callback when this Completable emits an error or completes.

public final Completable

Returns:

the new Completable instance
doOnError
(Action1<? super Throwable>
the error callback
onError
)

Returns a Completable which calls the given onError callback if this Completable emits an error.

protected final Completable

Returns:

the new Completable instance
doOnLifecycle
(final Action1<? super Subscription>
the consumer called when a CompletableSubscriber subscribes.
onSubscribe
,
final Action1<? super Throwable>
the consumer called when this emits an onError event
onError
,
final Action0
the runnable called just before when this Completable completes normally
onComplete
,
final Action0
the runnable called after this Completable terminates
onAfterTerminate
,
final Action0
the runnable called when the child cancels the subscription
onUnsubscribe
)

Returns a Completable instance that calls the various callbacks on the specific lifecycle events.

public final Completable

Returns:

the new Completable instance
doOnSubscribe
(Action1<? super Subscription>
the callback called when a child subscriber subscribes
onSubscribe
)

Returns a Completable instance that calls the given onSubscribe callback with the disposable that child subscribers receive on subscription.

public final Completable

Returns:

the new Completable instance
doOnTerminate
(final Action0
the callback to call just before this Completable terminates
onTerminate
)

Returns a Completable instance that calls the given onTerminate callback just before this Completable completes normally or with an exception

public final Completable

Returns:

the new Completable instance
doOnUnsubscribe
(Action0
the callback to call when the child subscriber cancels the subscription
onUnsubscribe
)

Returns a Completable which calls the given onUnsubscribe callback if the child subscriber cancels the subscription.

public static Completable

Returns:

the new Completable instance
error
(final Func0<? extends Throwable>
the error supplier, not null
errorFunc0
)

Creates a Completable which calls the given error supplier for each subscriber and emits its returned Throwable.

public static Completable

Returns:

the new Completable instance
error
(final Throwable
the Throwable instance to emit, not null
error
)

Creates a Completable instance that emits the given Throwable exception to subscribers.

public static Completable

Returns:

the new Completable instance
fromAction
(final Action0
the Action0 to run for each subscriber
action
)

Returns a Completable instance that runs the given Action0 for each subscriber and emits either an unchecked exception or simply completes.

public static Completable

Returns:

the new Completable instance
fromCallable
(final Callable<?>
the callable instance to execute for each subscriber
callable
)

Returns a Completable which when subscribed, executes the callable function, ignores its normal result and emits onError or onCompleted only.

public static Completable

Returns:

the new Completable instance
fromEmitter
(Action1<CompletableEmitter>
the callback invoked for each incoming CompletableSubscriber
producer
)

Provides an API (in a cold Completable) that bridges the Completable-reactive world with the callback-based world.

public static Completable

Returns:

the new Completable instance
fromFuture
(Future<?>
the future to react to
future
)

Returns a Completable instance that reacts to the termination of the given Future in a blocking fashion.

public static Completable

Returns:

the new Completable instance
fromObservable
(final Observable<?>
the Flowable instance to subscribe to, not null
flowable
)

Returns a Completable instance that subscribes to the given flowable, ignores all values and emits only the terminal event.

public static Completable

Returns:

the new Completable instance
fromSingle
(final Single<?>
the Single instance to subscribe to, not null
single
)

Returns a Completable instance that when subscribed to, subscribes to the Single instance and emits a completion event if the single emits onSuccess or forwards any onError events.

public final Throwable

Returns:

the throwable if this terminated with an error, null otherwise
get
()

Subscribes to this Completable instance and blocks until it terminates, then returns null or the emitted exception if any.

public final Throwable

Returns:

the throwable if this terminated with an error, null otherwise
get
(long
the time amount to wait for the terminal event
timeout
,
TimeUnit
the time unit of the timeout parameter
unit
)

Subscribes to this Completable instance and blocks until it terminates or the specified timeout elapses, then returns null for normal termination or the emitted exception if any.

public final Completable

Returns:

the new Completable instance
lift
(final Completable.Operator
the lifting function that transforms the child subscriber with a parent subscriber.
onLift
)

Lifts a CompletableSubscriber transformation into the chain of Completables.

public static Completable

Returns:

the new Completable instance
merge
(Completable...
the iterable sequence of sources.
sources
)

Returns a Completable instance that subscribes to all sources at once and completes only when all source Completables complete or one of them emits an error.

public static Completable

Returns:

the new Completable instance
merge
(Iterable<? extends Completable>
the iterable sequence of sources.
sources
)

Returns a Completable instance that subscribes to all sources at once and completes only when all source Completables complete or one of them emits an error.

public static Completable

Returns:

the new Completable instance
merge
(Observable<? extends Completable>
the iterable sequence of sources.
sources
)

Returns a Completable instance that subscribes to all sources at once and completes only when all source Completables complete or one of them emits an error.

public static Completable

Returns:

the new Completable instance
merge
(Observable<? extends Completable>
the iterable sequence of sources.
sources
,
int
the maximum number of concurrent subscriptions
maxConcurrency
)

Returns a Completable instance that keeps subscriptions to a limited number of sources at once and completes only when all source Completables complete or one of them emits an error.

protected static Completable

Returns:

the new Completable instance
merge0
(Observable<? extends Completable>
the iterable sequence of sources.
sources
,
int
the maximum number of concurrent subscriptions
maxConcurrency
,
boolean
delay all errors from the main source and from the inner Completables?
delayErrors
)

Returns a Completable instance that keeps subscriptions to a limited number of sources at once and completes only when all source Completables terminate in one way or another, combining any exceptions thrown by either the sources Observable or the inner Completable instances.

public static Completable

Returns:

the new Completable instance
mergeDelayError
(Completable...
the array of Completables
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.

public static Completable

Returns:

the new Completable instance
mergeDelayError
(Iterable<? extends Completable>
the sequence of Completables
sources
)

Returns a Completable that subscribes to all Completables in the source sequence and delays any error emitted by either the sources observable or any of the inner Completables until all of them terminate in a way or another.

public static Completable

Returns:

the new Completable instance
mergeDelayError
(Observable<? extends Completable>
the sequence of Completables
sources
)

Returns a Completable that subscribes to all Completables in the source sequence and delays any error emitted by either the sources observable or any of the inner Completables until all of them terminate in a way or another.

public static Completable

Returns:

the new Completable instance
mergeDelayError
(Observable<? extends Completable>
the sequence of Completables
sources
,
int
the maximum number of simultaneous subscriptions to the source Completables.
maxConcurrency
)

Returns a Completable that subscribes to a limited number of inner Completables at once in the source sequence and delays any error emitted by either the sources observable or any of the inner Completables until all of them terminate in a way or another.

public final Completable

Returns:

the new Completable instance
mergeWith
(Completable
the other Completable instance
other
)

Returns a Completable which subscribes to this and the other Completable and completes when both of them complete or one emits an error.

public static Completable

Returns:

the singleton instance that never calls onError or onComplete
never
()

Returns a Completable that never calls onError or onComplete.

public final Completable

Returns:

the new Completable instance
observeOn
(final Scheduler
the scheduler to emit terminal events on
scheduler
)

Returns a Completable which emits the terminal events from the thread of the specified scheduler.

public final Completable

Returns:

the new Completable instance
onErrorComplete
()

Returns a Completable instance that if this Completable emits an error, it will emit an onComplete and swallow the throwable.

public final Completable

Returns:

the new Completable instance
onErrorComplete
(final Func1<? super Throwable, Boolean>
the predicate to call when a Throwable is emitted which should return true if the Throwable should be swallowed and replaced with an onComplete.
predicate
)

Returns a Completable instance that if this Completable emits an error and the predicate returns true, it will emit an onComplete and swallow the throwable.

public final Completable

Returns:

the new Completable instance
onErrorResumeNext
(final Func1<? super Throwable, ? extends Completable>
the mapper function that takes the error and should return a Completable as continuation.
errorMapper
)

Returns a Completable instance that when encounters an error from this Completable, calls the specified mapper function that returns another Completable instance for it and resumes the execution with it.

public final Completable

Returns:

the new Completable instance
repeat
()

Returns a Completable that repeatedly subscribes to this Completable until cancelled.

public final Completable

Returns:

the new Completable instance
repeat
(long
the number of times the resubscription should happen
times
)

Returns a Completable that subscribes repeatedly at most the given times to this Completable.

public final Completable

Returns:

the new Completable instance
repeatWhen
(Func1<? super Observable<? extends Void>, ? extends Observable<?>>
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
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.

pack-priv static <T> T

Returns:

the o value
requireNonNull
(T
the object to check
o
)

Java 7 backport: throws a NullPointerException if o is null.

public final Completable

Returns:

the new Completable instance
retry
()

Returns a Completable that retries this Completable as long as it emits an onError event.

public final Completable

Returns:

the new Completable instance
retry
(Func2<Integer, Throwable, Boolean>
the predicate called when this emits an error with the repeat count and the latest exception and should return true to retry.
predicate
)

Returns a Completable that retries this Completable in case of an error as long as the predicate returns true.

public final Completable

Returns:

the new Completable instance
retry
(long
the number of times the returned Completable should retry this Completable
times
)

Returns a Completable that when this Completable emits an error, retries at most the given number of times before giving up and emitting the last error.

public final Completable

Returns:

the new Completable instance
retryWhen
(Func1<? super Observable<? extends Throwable>, ? extends Observable<?>>
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.
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.

public final Completable

Returns:

the new Completable instance
startWith
(Completable
the other completable to run first
other
)

Returns a Completable which first runs the other Completable then this completable if the other completed normally.

public final <
the value type of the starting other Observable
T
>
Observable<T>

Returns:

the new Observable instance
startWith
(Observable<T>
the other Observable to run first
other
)

Returns an Observable which first delivers the events of the other Observable then runs this Completable.

public final Subscription

Returns:

the Subscription that allows cancelling the subscription
subscribe
()

Subscribes to this Completable and returns a Subscription which can be used to cancel the subscription.

public final Subscription

Returns:

the Subscription that allows cancelling the subscription
subscribe
(final Action0
the runnable called when this Completable completes normally
onComplete
)

Subscribes to this Completable and calls the given Action0 when this Completable completes normally.

public final Subscription

Returns:

the Subscription that can be used for cancelling the subscription asynchronously
subscribe
(final Action0
the runnable that is called if the Completable completes normally
onComplete
,
final Action1<? super Throwable>
the consumer that is called if this Completable emits an error
onError
)

Subscribes to this Completable and calls back either the onError or onComplete functions.

public final void
subscribe(CompletableSubscriber
the CompletableSubscriber, not null
s
)

Subscribes the given CompletableSubscriber to this Completable instance and handles exceptions thrown by its onXXX methods.

public final <
the value type of the subscriber
T
>
void
subscribe(Subscriber<T>
the reactive-streams Subscriber, not null
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.

public final Completable

Returns:

the new Completable instance
subscribeOn
(final Scheduler
the Scheduler to subscribe on
scheduler
)

Returns a Completable which subscribes the child subscriber on the specified scheduler, making sure the subscription side-effects happen on that specific thread of the scheduler.

public final AssertableSubscriber<Void>

Returns:

the new AssertableSubscriber instance
test
()

Creates an AssertableSubscriber that requests Long.MAX_VALUE and subscribes it to this Observable.

public final Completable

Returns:

the new Completable instance
timeout
(long
the timeout value
timeout
,
TimeUnit
the timeout unit
unit
)

Returns a Completable that runs this Completable and emits a TimeoutException in case this Completable doesn't complete within the given time.

public final Completable

Returns:

the new Completable instance
timeout
(long
the timeout value
timeout
,
TimeUnit
the timeout unit
unit
,
Completable
the other Completable instance to switch to in case of a timeout
other
)

Returns a Completable that runs this Completable and switches to the other Completable in case this Completable doesn't complete within the given time.

public final Completable

Returns:

the new Completable instance
timeout
(long
the timeout value
timeout
,
TimeUnit
the timeout unit
unit
,
Scheduler
the scheduler to use to wait for completion
scheduler
)

Returns a Completable that runs this Completable and emits a TimeoutException in case this Completable doesn't complete within the given time while "waiting" on the specified Scheduler.

public final Completable

Returns:

the new Completable instance
timeout
(long
the timeout value
timeout
,
TimeUnit
the timeout unit
unit
,
Scheduler
the scheduler to use to wait for completion
scheduler
,
Completable
the other Completable instance to switch to in case of a timeout
other
)

Returns a Completable that runs this Completable and switches to the other Completable in case this Completable doesn't complete within the given time while "waiting" on the specified scheduler.

public final Completable

Returns:

the new Completable instance
timeout0
(long
the timeout value
timeout
,
TimeUnit
the timeout unit
unit
,
Scheduler
the scheduler to use to wait for completion
scheduler
,
Completable
the other Completable instance to switch to in case of a timeout, if null a TimeoutException is emitted instead
other
)

Returns a Completable that runs this Completable and optionally switches to the other Completable in case this Completable doesn't complete within the given time while "waiting" on the specified scheduler.

public static Completable

Returns:

the new Completable instance
timer
(long
the delay time
delay
,
TimeUnit
the delay unit
unit
)

Returns a Completable instance that fires its onComplete event after the given delay elapsed.

public static Completable

Returns:

the new Completable instance
timer
(final long
the delay time
delay
,
final TimeUnit
the delay unit
unit
,
final Scheduler
the scheduler to use to emit the onCompleted event
scheduler
)

Returns a Completable instance that fires its onCompleted event after the given delay elapsed by using the supplied scheduler.

public final <
the resulting object type
R
>
R

Returns:

the value returned by the function
to
(Func1<? super Completable, R>
the function that receives the current Single instance and returns a value
converter
)

Calls the specified converter function during assembly time and returns its resulting value.

pack-priv static NullPointerException

Returns:

the created NullPointerException
toNpe
(Throwable
the Throwable instance to use as cause, not null (not verified)
ex
)

Creates a NullPointerException instance and sets the given Throwable as its initial cause.

public final <
the target type of the Observable
T
>
Observable<T>

Returns:

the new Observable created
toObservable
()

Returns an Observable which when subscribed to subscribes to this Completable and relays the terminal events to the subscriber.

public final <
the value type of the resulting Single
T
>
Single<T>

Returns:

the new Single instance
toSingle
(final Func0<? extends T>
the value supplier called when this Completable completes normally
completionValueFunc0
)

Converts this Completable into a Single which when this Completable completes normally, calls the given supplier and emits its returned value through onSuccess.

public final <
the value type of the resulting Single
T
>
Single<T>

Returns:

the new Single instance
toSingleDefault
(final T
the value to emit when this Completable completes normally
completionValue
)

Converts this Completable into a Single which when this Completable completes normally, emits the given value through onSuccess.

public final void
unsafeSubscribe(CompletableSubscriber
the CompletableSubscriber, not null
s
)

Subscribes the given CompletableSubscriber to this Completable instance.

public final <
the value type of the subscriber
T
>
void
unsafeSubscribe(final Subscriber<T>
the reactive-streams Subscriber, not null
s
)

Subscribes a regular Subscriber to this Completable instance which will receive only an onError or onComplete event.

private <
the value type of the subscriber
T
>
void
unsafeSubscribe(final Subscriber<T>
the subscriber instance, not null
s
,
boolean
if true, the Subscriber.onStart will be called
callOnStart
)

Performs the actual unsafe subscription and calls the onStart if required.

public final Completable

Returns:

the new Completable instance
unsubscribeOn
(final Scheduler
the target scheduler where to execute the cancellation
scheduler
)

Returns a Completable which makes sure when a subscriber cancels the subscription, the dispose is called on the specified scheduler

public static <
the resource type
R
>
Completable

Returns:

the new Completable instance
using
(Func0<R>
the supplier that returns a resource to be managed.
resourceFunc0
,
Func1<? super R, ? extends Completable>
the function that given a resource returns a Completable instance that will be subscribed to
completableFunc1
,
Action1<? super R>
the consumer that disposes the resource created by the resource supplier
disposer
)

Returns a Completable instance which manages a resource along with a custom Completable instance while the subscription is active.

public static <
the resource type
R
>
Completable

Returns:

the new Completable instance
using
(final Func0<R>
the supplier that returns a resource to be managed
resourceFunc0
,
final Func1<? super R, ? extends Completable>
the function that given a resource returns a non-null Completable instance that will be subscribed to
completableFunc1
,
final Action1<? super R>
the consumer that disposes the resource created by the resource supplier
disposer
,
final boolean
if true, the resource is disposed before the terminal event is emitted, if false, the resource is disposed after the terminal event has been emitted
eager
)

Returns a Completable instance which manages a resource along with a custom Completable instance while the subscription is active and performs eager or lazy resource disposition.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait