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. 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 io.reactivex.rxjava3.core.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
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
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final CompletableSubject. | |
| pack-priv Throwable | |
| pack-priv final AtomicReference | |
| pack-priv final AtomicBoolean | |
| pack-priv static final CompletableSubject. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv boolean | |
| public static @NonNull CompletableSubject | |
| public @Nullable Throwable | Returns: the terminal error or null if not terminated or not with an errorReturns the terminal error if this CompletableSubject has been terminated with an error, null otherwise. |
| public boolean | Returns: true if this CompletableSubject has been completedReturns true if this CompletableSubject has been completed. |
| public boolean | Returns: true if this CompletableSubject has observersReturns true if this CompletableSubject has observers. |
| public boolean | Returns: true if this CompletableSubject has been terminated with an errorReturns true if this CompletableSubject has been terminated with an error. |
| pack-priv int | |
| public void | onComplete()
Implements io. |
| public void | |
| public void | |
| pack-priv void | |
| protected void |
| EMPTY | back to summary |
|---|---|
| pack-priv static final CompletableSubject. | |
| error | back to summary |
|---|---|
| pack-priv Throwable error | |
| observers | back to summary |
|---|---|
| pack-priv final AtomicReference<CompletableSubject. | |
| once | back to summary |
|---|---|
| pack-priv final AtomicBoolean once | |
| TERMINATED | back to summary |
|---|---|
| pack-priv static final CompletableSubject. | |
| CompletableSubject | back to summary |
|---|---|
| pack-priv CompletableSubject() | |
| add | back to summary |
|---|---|
| pack-priv boolean add(CompletableSubject. | |
| create | back to summary |
|---|---|
| public static @NonNull CompletableSubject create() Creates a fresh CompletableSubject.
| |
| getThrowable | back to summary |
|---|---|
| public @Nullable Throwable getThrowable() Returns the terminal error if this CompletableSubject has been terminated with an error, null otherwise. | |
| hasComplete | back to summary |
|---|---|
| public boolean hasComplete() Returns true if this CompletableSubject has been completed.
| |
| hasObservers | back to summary |
|---|---|
| public boolean hasObservers() Returns true if this CompletableSubject has observers.
| |
| hasThrowable | back to summary |
|---|---|
| public boolean hasThrowable() Returns true if this CompletableSubject has been terminated with an error.
| |
| observerCount | back to summary |
|---|---|
| pack-priv int observerCount() Returns the number of current observers.
| |
| onComplete | back to summary |
|---|---|
| public void onComplete() Implements io. Doc from io. Called once the deferred computation completes normally.
| |
| onError | back to summary |
|---|---|
public void onError(Throwable e)
| |
| onSubscribe | back to summary |
|---|---|
public void onSubscribe(Disposable d)
| |
| remove | back to summary |
|---|---|
| pack-priv void remove(CompletableSubject. | |
| subscribeActual | back to summary |
|---|---|
protected void subscribeActual(CompletableObserver observer)
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final CompletableObserver | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | dispose()
Implements io. |
| public boolean | isDisposed()
Implements io. |
| downstream | back to summary |
|---|---|
| pack-priv final CompletableObserver downstream | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. | |
| CompletableDisposable | back to summary |
|---|---|
| pack-priv CompletableDisposable(CompletableObserver actual, CompletableSubject parent) | |
| dispose | back to summary |
|---|---|
| public void dispose() Implements io. Doc from io. Dispose the resource, the operation should be idempotent.
| |
| isDisposed | back to summary |
|---|---|
| public boolean isDisposed() Implements io. Doc from io. Returns true if this resource has been disposed.
| |