This subject does not have a public constructor by design; a new non-terminated instance of this
MaybeSubject can be created via the create() method.
Since the MaybeSubject is conceptionally derived from the Processor type in the Reactive Streams specification,
nulls are not allowed (Rule 2.13)
as parameters to onSuccess(Object) and onError(Throwable). Such calls will result in a
NullPointerException being thrown and the subject's state is not changed.
Since a MaybeSubject is a io., calling onSuccess, onError
or onComplete will move this MaybeSubject into its terminal state atomically.
All methods are thread safe. Calling onSuccess(Object) or onComplete() multiple
times has no effect. Calling onError(Throwable) multiple times relays the Throwable to
the io. global error handler.
Even though MaybeSubject implements the MaybeObserver interface, calling
onSubscribe is not required (Rule 2.12)
if the subject is used as a standalone source. However, calling onSubscribe
after the MaybeSubject reached its terminal state will result in the
given Disposable being disposed immediately.
This MaybeSubject supports the standard state-peeking methods hasComplete(), hasThrowable(),
getThrowable() and hasObservers() as well as means to read any success item in a non-blocking
and thread-safe manner via hasValue() and getValue().
The MaybeSubject does not support clearing its cached onSuccess value.
MaybeSubject does not operate by default on a particular io.reactivex.rxjava3.core.Scheduler and
the MaybeObservers get notified on the thread where the terminating onSuccess, onError or onComplete
methods were invoked.onError(Throwable) is called, the MaybeSubject enters into a terminal state
and emits the same Throwable instance to the last set of MaybeObservers. During this emission,
if one or more MaybeObservers 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 MaybeObservers
cancel at once).
If there were no MaybeObservers subscribed to this MaybeSubject when the onError()
was called, the global error handler is not invoked.
Example usage:
MaybeSubject<Integer> subject1 = MaybeSubject.create();
TestObserver<Integer> to1 = subject1.test();
// MaybeSubjects are empty by default
to1.assertEmpty();
subject1.onSuccess(1);
// onSuccess is a terminal event with MaybeSubjects
// TestObserver converts onSuccess into onNext + onComplete
to1.assertResult(1);
TestObserver<Integer> to2 = subject1.test();
// late Observers receive the terminal signal (onSuccess) too
to2.assertResult(1);
// -----------------------------------------------------
MaybeSubject<Integer> subject2 = MaybeSubject.create();
TestObserver<Integer> to3 = subject2.test();
subject2.onComplete();
// a completed MaybeSubject completes its MaybeObservers
to3.assertResult();
TestObserver<Integer> to4 = subject1.test();
// late Observers receive the terminal signal (onComplete) too
to4.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 MaybeSubject. | |
| pack-priv Throwable | |
| pack-priv final AtomicReference | |
| pack-priv final AtomicBoolean | |
| pack-priv static final MaybeSubject. | |
| pack-priv T |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv boolean | |
| public static < the value type received and emitted T> @NonNull MaybeSubject | |
| public @Nullable Throwable | Returns: the terminal error or null if not terminated or not with an errorReturns the terminal error if this MaybeSubject has been terminated with an error, null otherwise. |
| public T | Returns: the success value or nullReturns the success value if this MaybeSubject was terminated with a success value. |
| public boolean | Returns: true if this MaybeSubject has been completedReturns true if this MaybeSubject has been completed. |
| public boolean | Returns: true if this MaybeSubject has observersReturns true if this MaybeSubject has observers. |
| public boolean | Returns: true if this MaybeSubject has been terminated with an errorReturns true if this MaybeSubject has been terminated with an error. |
| public boolean | Returns: true if this MaybeSubject was terminated with a success valueReturns true if this MaybeSubject was terminated with a success value. |
| pack-priv int | |
| public void | onComplete()
Implements io. |
| public void | |
| public void | |
| public void | onSuccess(T
the item emitted by the value)MaybeImplements io. MaybeObserver with one item and that the Maybe has finished sending
push-based notifications.
|
| pack-priv void | |
| protected void |
| EMPTY | back to summary |
|---|---|
pack-priv static final MaybeSubject.
| |
| error | back to summary |
|---|---|
| pack-priv Throwable error | |
| observers | back to summary |
|---|---|
| pack-priv final AtomicReference<MaybeSubject. | |
| once | back to summary |
|---|---|
| pack-priv final AtomicBoolean once | |
| TERMINATED | back to summary |
|---|---|
pack-priv static final MaybeSubject.
| |
| value | back to summary |
|---|---|
| pack-priv T value | |
| MaybeSubject | back to summary |
|---|---|
pack-priv MaybeSubject()
| |
| add | back to summary |
|---|---|
| pack-priv boolean add(MaybeSubject. | |
| create | back to summary |
|---|---|
| public static <T> @NonNull MaybeSubject Creates a fresh MaybeSubject.
| |
| getThrowable | back to summary |
|---|---|
| public @Nullable Throwable getThrowable() Returns the terminal error if this MaybeSubject has been terminated with an error, null otherwise. | |
| getValue | back to summary |
|---|---|
| public T getValue() Returns the success value if this MaybeSubject was terminated with a success value.
| |
| hasComplete | back to summary |
|---|---|
| public boolean hasComplete() Returns true if this MaybeSubject has been completed.
| |
| hasObservers | back to summary |
|---|---|
| public boolean hasObservers() Returns true if this MaybeSubject has observers.
| |
| hasThrowable | back to summary |
|---|---|
| public boolean hasThrowable() Returns true if this MaybeSubject has been terminated with an error.
| |
| hasValue | back to summary |
|---|---|
| public boolean hasValue() Returns true if this MaybeSubject was terminated with a success value.
| |
| 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)
| |
| onSuccess | back to summary |
|---|---|
| public void onSuccess(T value) Implements io. Doc from io. Notifies the
The
| |
| remove | back to summary |
|---|---|
pack-priv void remove(MaybeSubject.
| |
| subscribeActual | back to summary |
|---|---|
protected void subscribeActual(MaybeObserver<? super T> observer)
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final MaybeObserver | |
| 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 MaybeObserver<? super T> downstream | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. | |
| MaybeDisposable | back to summary |
|---|---|
| pack-priv MaybeDisposable(MaybeObserver<? super T> actual, MaybeSubject<T> 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.
| |