Top Description Inners Fields Constructors Methods
io.reactivex.rxjava3.subjects

public final Class CompletableSubject

extends Completable
implements CompletableObserver
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.core.CompletableObserver
Imports
java.util.concurrent.atomic.*, io.reactivex.rxjava3.annotations.*, io.reactivex.rxjava3.core.*, io.reactivex.rxjava3.disposables.Disposable, io.reactivex.rxjava3.internal.util.ExceptionHelper, io.reactivex.rxjava3.plugins.RxJavaPlugins

Represents a hot Completable-like source and consumer of events similar to Subjects.

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 io.reactivex.rxjava3.plugins.RxJavaPlugins#onError(Throwable) global error handler.

This CompletableSubject supports the standard state-peeking methods hasComplete(), hasThrowable(), getThrowable() and hasObservers().

Scheduler:
CompletableSubject does not operate by default on a particular io.reactivex.rxjava3.core.Scheduler and the CompletableObservers get notified on the thread where the terminating onError or onComplete methods were invoked.
Error handling:
When the 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 io.reactivex.rxjava3.plugins.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

Since
2.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static final CompletableSubject.CompletableDisposable[]
pack-priv Throwable
pack-priv final AtomicReference<CompletableSubject.CompletableDisposable[]>
pack-priv final AtomicBoolean
pack-priv static final CompletableSubject.CompletableDisposable[]

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
public static @NonNull CompletableSubject

Returns:

the new CompletableSubject instance
create
()

Creates a fresh CompletableSubject.

public @Nullable Throwable

Returns:

the terminal error or null if not terminated or not with an error
getThrowable
()

Returns the terminal error if this CompletableSubject has been terminated with an error, null otherwise.

public boolean

Returns:

true if this CompletableSubject has been completed
hasComplete
()

Returns true if this CompletableSubject has been completed.

public boolean

Returns:

true if this CompletableSubject has observers
hasObservers
()

Returns true if this CompletableSubject has observers.

public boolean

Returns:

true if this CompletableSubject has been terminated with an error
hasThrowable
()

Returns true if this CompletableSubject has been terminated with an error.

pack-priv int

Returns:

the number of current observers
observerCount
()

Returns the number of current observers.

public void
onComplete()

Implements io.reactivex.rxjava3.core.CompletableObserver.onComplete.

Called once the deferred computation completes normally.
public void
public void
pack-priv void
protected void
Inherited from io.reactivex.rxjava3.core.Completable:
ambambArrayambWithandThenandThenandThenandThenandThenblockingAwaitblockingAwaitblockingSubscribeblockingSubscribeblockingSubscribeblockingSubscribecachecompletecomposeconcatconcatconcatconcatArrayconcatArrayDelayErrorconcatDelayErrorconcatDelayErrorconcatDelayErrorconcatWithcreatedeferdelaydelaydelaydelaySubscriptiondelaySubscriptiondoAfterTerminatedoFinallydoOnCompletedoOnDisposedoOnErrordoOnEventdoOnLifecycledoOnSubscribedoOnTerminateerrorerrorfromActionfromCallablefromCompletionStagefromFuturefromMaybefromObservablefromPublisherfromRunnablefromSinglefromSupplierhideliftmaterializemergemergemergemergeArraymergeArrayDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeWithneverobserveOnonErrorCompleteonErrorCompleteonErrorResumeNextonErrorResumeWithonErrorReturnonErrorReturnItemonTerminateDetachrepeatrepeatrepeatUntilrepeatWhenretryretryretryretryretryretryUntilretryWhensafeSubscribesequenceEqualstartWithstartWithstartWithstartWithstartWithsubscribesubscribesubscribesubscribesubscribesubscribeActualsubscribeOnsubscribeWithswitchOnNextswitchOnNextDelayErrortakeUntiltesttesttimeouttimeouttimeouttimeouttimertimertotoCompletionStagetoFlowabletoFuturetoMaybetoObservabletoSingletoSingleDefaultunsafeCreateunsubscribeOnusingusingwrap

Field Detail

EMPTYback to summary
pack-priv static final CompletableSubject.CompletableDisposable[] EMPTY
errorback to summary
pack-priv Throwable error
observersback to summary
pack-priv final AtomicReference<CompletableSubject.CompletableDisposable[]> observers
onceback to summary
pack-priv final AtomicBoolean once
TERMINATEDback to summary
pack-priv static final CompletableSubject.CompletableDisposable[] TERMINATED

Constructor Detail

CompletableSubjectback to summary
pack-priv CompletableSubject()

Method Detail

addback to summary
pack-priv boolean add(CompletableSubject.CompletableDisposable inner)
createback to summary
public static @NonNull CompletableSubject create()

Creates a fresh CompletableSubject.

Returns:@NonNull CompletableSubject

the new CompletableSubject instance

Annotations
@CheckReturnValue
@NonNull
getThrowableback to summary
public @Nullable Throwable getThrowable()

Returns the terminal error if this CompletableSubject has been terminated with an error, null otherwise.

Returns:@Nullable Throwable

the terminal error or null if not terminated or not with an error

Annotations
@Nullable
hasCompleteback to summary
public boolean hasComplete()

Returns true if this CompletableSubject has been completed.

Returns:boolean

true if this CompletableSubject has been completed

hasObserversback to summary
public boolean hasObservers()

Returns true if this CompletableSubject has observers.

Returns:boolean

true if this CompletableSubject has observers

hasThrowableback to summary
public boolean hasThrowable()

Returns true if this CompletableSubject has been terminated with an error.

Returns:boolean

true if this CompletableSubject has been terminated with an error

observerCountback to summary
pack-priv int observerCount()

Returns the number of current observers.

Returns:int

the number of current observers

onCompleteback to summary
public void onComplete()

Implements io.reactivex.rxjava3.core.CompletableObserver.onComplete.

Doc from io.reactivex.rxjava3.core.CompletableObserver.onComplete.

Called once the deferred computation completes normally.

Annotations
@Override
onErrorback to summary
public void onError(Throwable e)
Annotations
@Override
onSubscribeback to summary
public void onSubscribe(Disposable d)
Annotations
@Override
removeback to summary
pack-priv void remove(CompletableSubject.CompletableDisposable inner)
subscribeActualback to summary
protected void subscribeActual(CompletableObserver observer)
Annotations
@Override
io.reactivex.rxjava3.subjects back to summary

pack-priv final Class CompletableSubject.CompletableDisposable

extends AtomicReference<CompletableSubject>
implements Disposable
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.disposables.Disposable

Field Summary

Modifier and TypeField and Description
pack-priv final CompletableObserver
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.
public boolean
isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.
Inherited from java.util.concurrent.atomic.AtomicReference:
accumulateAndGetcompareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetgetgetAcquiregetAndAccumulategetAndSetgetAndUpdategetOpaquegetPlainlazySetsetsetOpaquesetPlainsetReleasetoStringupdateAndGetweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

downstreamback to summary
pack-priv final CompletableObserver downstream
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.atomic.AtomicReference.serialVersionUID.

Constructor Detail

CompletableDisposableback to summary
pack-priv CompletableDisposable(CompletableObserver actual, CompletableSubject parent)

Method Detail

disposeback to summary
public void dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Doc from io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Doc from io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.

Returns:boolean

true if this resource has been disposed

Annotations
@Override