Top Description Fields Constructors Methods
rx.subjects

public final Class AsyncSubject<T>

extends Subject<T, T>
Class Inheritance
Type Parameters
<T>
the type of item expected to be observed by the Subject
Imports
java.util.*, rx.Observer, rx.exceptions.Exceptions, rx.functions.Action1, rx.internal.operators.NotificationLite, rx.internal.producers.SingleProducer, rx.subjects.SubjectSubscriptionManager.SubjectObserver

Subject that publishes only the last item observed to each Observer once the source Observable has completed. The item is cached and published to any Observers which subscribe after the source has completed. If the source emitted no items, AsyncSubject completes without emitting anything. If the source terminated in an error, current and future subscribers will receive only the error.

Example usage:

 // observer will receive no onNext events because the subject.onCompleted() isn't called.
 AsyncSubject<Object> subject = AsyncSubject.create();
 subject.subscribe(observer);
 subject.onNext("one");
 subject.onNext("two");
 subject.onNext("three");

 // observer will receive "three" as the only onNext event.
 AsyncSubject<Object> subject = AsyncSubject.create();
 subject.subscribe(observer);
 subject.onNext("one");
 subject.onNext("two");
 subject.onNext("three");
 subject.onCompleted();

  

Field Summary

Modifier and TypeField and Description
pack-priv volatile Object
pack-priv final SubjectSubscriptionManager<T>

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public static <
the result value type
T
>
AsyncSubject<T>

Returns:

the new AsyncSubject
create
()

Creates and returns a new AsyncSubject.

public Throwable

Returns:

the Throwable that terminated the Subject or null if the subject hasn't terminated yet or it terminated normally.
getThrowable
()

Returns the Throwable that terminated the Subject.

public T

Returns:

the current value or null if the Subject doesn't have a value, has terminated with an exception or has an actual null as a value.
getValue
()

Returns the current value of the Subject if there is such a value and the subject hasn't terminated with an exception.

public boolean

Returns:

true if the subject completed normally via onCompleted()
hasCompleted
()

Check if the Subject has terminated normally.

public boolean
hasObservers()

Implements abstract rx.subjects.Subject.hasObservers.

Indicates whether the Subject has Observers subscribed to it.
public boolean

Returns:

true if the subject has received a throwable through onError.
hasThrowable
()

Check if the Subject has terminated with an exception.

public boolean

Returns:

true if and only if the subject has some value but not an error
hasValue
()

Check if the Subject has a value.

public void
onCompleted()

Implements rx.Observer.onCompleted.

Notifies the Observer that the Observable has finished sending push-based notifications.
public void
onError(final Throwable
the exception encountered by the Observable
e
)

Implements rx.Observer.onError.

Notifies the Observer that the Observable has experienced an error condition.
public void
onNext(T
the item emitted by the Observable
v
)

Implements rx.Observer.onNext.

Provides the Observer with a new item to observe.
Inherited from rx.subjects.Subject:
toSerialized

Field Detail

lastValueback to summary
pack-priv volatile Object lastValue
stateback to summary
pack-priv final SubjectSubscriptionManager<T> state

Constructor Detail

AsyncSubjectback to summary
protected AsyncSubject(Observable.OnSubscribe<T> onSubscribe, SubjectSubscriptionManager<T> state)

Method Detail

createback to summary
public static <T> AsyncSubject<T> create()

Creates and returns a new AsyncSubject.

Parameters
<T>
the result value type
Returns:AsyncSubject<T>

the new AsyncSubject

getThrowableback to summary
public Throwable getThrowable()

Returns the Throwable that terminated the Subject.

Returns:Throwable

the Throwable that terminated the Subject or null if the subject hasn't terminated yet or it terminated normally.

Since
1.2
getValueback to summary
public T getValue()

Returns the current value of the Subject if there is such a value and the subject hasn't terminated with an exception.

The method can return null for various reasons. Use hasValue(), hasThrowable() and hasCompleted() to determine if such null is a valid value, there was an exception or the Subject terminated without receiving any value.

Returns:T

the current value or null if the Subject doesn't have a value, has terminated with an exception or has an actual null as a value.

Since
1.2
hasCompletedback to summary
public boolean hasCompleted()

Check if the Subject has terminated normally.

Returns:boolean

true if the subject completed normally via onCompleted()

Since
1.2
hasObserversback to summary
public boolean hasObservers()

Implements abstract rx.subjects.Subject.hasObservers.

Doc from rx.subjects.Subject.hasObservers.

Indicates whether the Subject has Observers subscribed to it.

Returns:boolean

true if there is at least one Observer subscribed to this Subject, false otherwise

Annotations
@Override
hasThrowableback to summary
public boolean hasThrowable()

Check if the Subject has terminated with an exception.

Returns:boolean

true if the subject has received a throwable through onError.

Since
1.2
hasValueback to summary
public boolean hasValue()

Check if the Subject has a value.

Use the getValue() method to retrieve such a value.

Note that unless hasCompleted() or hasThrowable() returns true, the value retrieved by getValue() may get outdated.

Returns:boolean

true if and only if the subject has some value but not an error

Since
1.2
onCompletedback to summary
public void onCompleted()

Implements rx.Observer.onCompleted.

Doc from rx.Observer.onCompleted.

Notifies the Observer that the Observable has finished sending push-based notifications.

The Observable will not call this method if it calls onError.

Annotations
@Override
onErrorback to summary
public void onError(final Throwable e)

Implements rx.Observer.onError.

Doc from rx.Observer.onError.

Notifies the Observer that the Observable has experienced an error condition.

If the Observable calls this method, it will not thereafter call onNext or onCompleted.

Parameters
e:Throwable

the exception encountered by the Observable

Annotations
@Override
onNextback to summary
public void onNext(T v)

Implements rx.Observer.onNext.

Doc from rx.Observer.onNext.

Provides the Observer with a new item to observe.

The Observable may call this method 0 or more times.

The Observable will not call this method again after it calls either onCompleted or onError.

Parameters
v:T

the item emitted by the Observable

Annotations
@Override