public final class

SingleSubject

extends Single<T>
implements SingleObserver<T>
java.lang.Object
   ↳ io.reactivex.Single<T>
     ↳ io.reactivex.subjects.SingleSubject<T>

Class Overview

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

All methods are thread safe. Calling onSuccess multiple times has no effect. Calling onError multiple times relays the Throwable to the RxJavaPlugins' error handler.

The SingleSubject doesn't store the Disposables coming through onSubscribe but disposes them once the other onXXX methods were called (terminal state reached).

History: 2.0.5 - experimental

Summary

Public Methods
static <T> SingleSubject<T> create()
Creates a fresh SingleSubject.
Throwable getThrowable()
Returns the terminal error if this SingleSubject has been terminated with an error, null otherwise.
T getValue()
Returns the success value if this SingleSubject was terminated with a success value.
boolean hasObservers()
Returns true if this SingleSubject has observers.
boolean hasThrowable()
Returns true if this SingleSubject has been terminated with an error.
boolean hasValue()
Returns true if this SingleSubject was terminated with a success value.
void onError(Throwable e)
Notifies the SingleObserver that the Single has experienced an error condition.
void onSubscribe(Disposable d)
Provides the SingleObserver with the means of cancelling (disposing) the connection (channel) with the Single in both synchronous (from within onSubscribe(Disposable) itself) and asynchronous manner.
void onSuccess(T value)
Notifies the SingleObserver with a single item and that the Single has finished sending push-based notifications.
Protected Methods
void subscribeActual(SingleObserver<? super T> observer)
Override this method in subclasses to handle the incoming SingleObservers.
[Expand]
Inherited Methods
From class io.reactivex.Single
From class java.lang.Object
From interface io.reactivex.SingleObserver
From interface io.reactivex.SingleSource

Public Methods

public static SingleSubject<T> create ()

Creates a fresh SingleSubject.

Returns
  • the new SingleSubject instance

public Throwable getThrowable ()

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

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

public T getValue ()

Returns the success value if this SingleSubject was terminated with a success value.

Returns
  • the success value or null

public boolean hasObservers ()

Returns true if this SingleSubject has observers.

Returns
  • true if this SingleSubject has observers

public boolean hasThrowable ()

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

Returns
  • true if this SingleSubject has been terminated with an error

public boolean hasValue ()

Returns true if this SingleSubject was terminated with a success value.

Returns
  • true if this SingleSubject was terminated with a success value

public void onError (Throwable e)

Notifies the SingleObserver that the Single has experienced an error condition.

If the Single calls this method, it will not thereafter call onSuccess(T).

Parameters
e the exception encountered by the Single

public void onSubscribe (Disposable d)

Provides the SingleObserver with the means of cancelling (disposing) the connection (channel) with the Single in both synchronous (from within onSubscribe(Disposable) itself) and asynchronous manner.

Parameters
d the Disposable instance whose dispose() can be called anytime to cancel the connection

public void onSuccess (T value)

Notifies the SingleObserver with a single item and that the Single has finished sending push-based notifications.

The Single will not call this method if it calls onError(Throwable).

Parameters
value the item emitted by the Single

Protected Methods

protected void subscribeActual (SingleObserver<? super T> observer)

Override this method in subclasses to handle the incoming SingleObservers.

Parameters
observer the SingleObserver to handle, not null