-
Notifications
You must be signed in to change notification settings - Fork 2
Subject
A Subject
is a sort of bridge or proxy that acts both as an Observer
and as an Observable
. Because it is an Observer, it can subscribe to one or more Observables, and because it is an Observable, it can pass through the items it observes by reemitting them, and it can also emit new items.
There are four subclasses of Subject
that are designed for particular use cases:
AsyncSubject
emits the last value (and only the last value) emitted by the source Observable, and only after that source Observable completes. (If the source Observable does not emit any values, the AsyncSubject
also completes without emitting any values.)
It will also emit this same final value to any subsequent observers. However, if the source Observable terminates with an error, the
AsyncSubject
will not emit any items, but will simply pass along the error notification from the source Observable.
- javadoc:
AsyncSubject
- Reactive Extensions:
AsyncSubject
- Introduction to Rx: AsyncSubject
When an Observer subscribes to a BehaviorSubject
, it begins by emitting the item most recently emitted by the source Observable (or a seed/default value if none has yet been emitted) and then continues to emit any other items emitted later by the source Observable(s).
However, if the source Observable terminates with an error, the
BehaviorSubject
will not emit any items to subsequent observers, but will simply pass along the error notification from the source Observable.
- javadoc:
BehaviorSubject
- Reactive Extensions:
BehaviorSubject
- Introduction to Rx: BehaviorSubject
PublishSubject
emits to a subscriber only those items that are emitted by the source Observable(s) subsequent to the time of the subscription.
If the source Observable terminates with an error, the
PublishSubject
will not emit any items to subsequent observers, but will simply pass along the error notification from the source Observable.
- javadoc:
PublishSubject
ReplaySubject
emits to any subscriber all of the items that were emitted by the source Observable(s), regardless of when the subscriber subscribes.
- javadoc:
ReplaySubject
- Reactive Extensions:
ReplaySubject
- Introduction to Rx: ReplaySubject
A Netflix Original Production
Tech Blog | Twitter @NetflixOSS | Twitter @RxJava | Jobs