public final class CompletableSubject extends Completable implements CompletableObserver
This subject does not have a public constructor by design; a new non-terminated instance of this
CompletableSubject can be created via the create() method.
Since the CompletableSubject is conceptionally derived from the Processor type in the Reactive Streams specification,
nulls are not allowed (Rule 2.13)
as parameters to onError(Throwable).
Even though CompletableSubject implements the CompletableObserver interface, calling
onSubscribe is not required (Rule 2.12)
if the subject is used as a standalone source. However, calling onSubscribe
after the CompletableSubject reached its terminal state will result in the
given Disposable being disposed immediately.
All methods are thread safe. Calling onComplete() multiple
times has no effect. Calling onError(Throwable) multiple times relays the Throwable to
the RxJavaPlugins.onError(Throwable) global error handler.
This CompletableSubject supports the standard state-peeking methods hasComplete(),
hasThrowable(), getThrowable() and hasObservers().
CompletableSubject does not operate by default on a particular Scheduler and
the CompletableObservers get notified on the thread where the terminating onError or onComplete
methods were invoked.onError(Throwable) is called, the CompletableSubject enters into a terminal state
and emits the same Throwable instance to the last set of CompletableObservers. During this emission,
if one or more CompletableObservers dispose their respective Disposables, the
Throwable is delivered to the global error handler via
RxJavaPlugins.onError(Throwable) (multiple times if multiple CompletableObservers
cancel at once).
If there were no CompletableObservers subscribed to this CompletableSubject when the onError()
was called, the global error handler is not invoked.
Example usage:
CompletableSubject subject = CompletableSubject.create();
TestObserver<Void> to1 = subject.test();
// a fresh CompletableSubject is empty
to1.assertEmpty();
subject.onComplete();
// a CompletableSubject is always void of items
to1.assertResult();
TestObserver<Void> to2 = subject.test()
// late CompletableObservers receive the terminal event
to2.assertResult();
History: 2.0.5 - experimental
| Modifier and Type | Method and Description |
|---|---|
static CompletableSubject |
create()
Creates a fresh CompletableSubject.
|
Throwable |
getThrowable()
Returns the terminal error if this CompletableSubject has been terminated with an error, null otherwise.
|
boolean |
hasComplete()
Returns true if this CompletableSubject has been completed.
|
boolean |
hasObservers()
Returns true if this CompletableSubject has observers.
|
boolean |
hasThrowable()
Returns true if this CompletableSubject has been terminated with an error.
|
void |
onComplete()
Called once the deferred computation completes normally.
|
void |
onError(Throwable e)
Called once if the deferred computation 'throws' an exception.
|
void |
onSubscribe(Disposable d)
Called once by the Completable to set a Disposable on this instance which
then can be used to cancel the subscription at any time.
|
protected void |
subscribeActual(CompletableObserver observer)
Implement this method to handle the incoming
CompletableObservers and
perform the business logic in your operator. |
amb, ambArray, ambWith, andThen, andThen, andThen, andThen, andThen, as, blockingAwait, blockingAwait, blockingGet, blockingGet, cache, complete, compose, concat, concat, concat, concatArray, concatWith, create, defer, delay, delay, delay, doAfterTerminate, doFinally, doOnComplete, doOnDispose, doOnError, doOnEvent, doOnSubscribe, doOnTerminate, error, error, fromAction, fromCallable, fromFuture, fromObservable, fromPublisher, fromRunnable, fromSingle, hide, lift, merge, merge, merge, mergeArray, mergeArrayDelayError, mergeDelayError, mergeDelayError, mergeDelayError, mergeWith, never, observeOn, onErrorComplete, onErrorComplete, onErrorResumeNext, onTerminateDetach, repeat, repeat, repeatUntil, repeatWhen, retry, retry, retry, retry, retry, retryWhen, startWith, startWith, startWith, subscribe, subscribe, subscribe, subscribe, subscribeOn, subscribeWith, test, test, timeout, timeout, timeout, timeout, timer, timer, to, toFlowable, toMaybe, toObservable, toSingle, toSingleDefault, unsafeCreate, unsubscribeOn, using, using, wrap@CheckReturnValue @NonNull public static CompletableSubject create()
public void onSubscribe(Disposable d)
CompletableObserveronSubscribe in interface CompletableObserverd - the Disposable instance to call dispose on for cancellation, not nullpublic void onError(Throwable e)
CompletableObserveronError in interface CompletableObservere - the exception, not null.public void onComplete()
CompletableObserveronComplete in interface CompletableObserverprotected void subscribeActual(CompletableObserver observer)
CompletableCompletableObservers and
perform the business logic in your operator.
There is no need to call any of the plugin hooks on the current Completable instance or
the CompletableObserver; all hooks and basic safeguards have been
applied by Completable.subscribe(CompletableObserver) before this method gets called.
subscribeActual in class Completableobserver - the CompletableObserver instance, never null@Nullable public Throwable getThrowable()
public boolean hasThrowable()
public boolean hasComplete()
public boolean hasObservers()