package subjects
Subjects are Observers and Observables at the same time.
- Alphabetic
- By Inheritance
- subjects
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- class AsyncSubject [T] extends Subject[T]
- class BehaviorSubject [T] extends Subject[T]
- class ReplaySubject [T] extends Subject[T]
- class SerializedSubject [T] extends Subject[T]
- class TestSubject [T] extends Subject[T]
Value Members
-
object
AsyncSubject
Subject that publishes only the last item observed to each
Observerthat has subscribed, when the sourceObservable}completes.Subject that publishes only the last item observed to each
Observerthat has subscribed, when the sourceObservable}completes.
// observer will receive no onNext events because the subject.onCompleted() isn't called. val subject = AsyncSubject[String]() subject.subscribe(observer) subject.onNext("one") subject.onNext("two") subject.onNext("three") // observer will receive "three" as the only onNext event. val subject = AsyncSubject[String]() subject.subscribe(observer) subject.onNext("one") subject.onNext("two") subject.onNext("three") subject.onCompleted()
Example: -
object
BehaviorSubject
Subject that emits the most recent item it has observed and all subsequent observed items to each subscribed
Observer.Subject that emits the most recent item it has observed and all subsequent observed items to each subscribed
Observer.
// observer will receive all events. val subject = BehaviorSubject[String]("default") subject.subscribe(observer) subject.onNext("one") subject.onNext("two") subject.onNext("three") // observer will receive the "one", "two" and "three" events, but not "zero" val subject = BehaviorSubject[String]("default") subject.onNext("zero") subject.onNext("one") subject.subscribe(observer) subject.onNext("two") subject.onNext("three") // observer will receive only onCompleted val subject = BehaviorSubject[String]("default") subject.onNext("zero") subject.onNext("one") subject.onCompleted() subject.subscribe(observer) // observer will receive only onError val subject = BehaviorSubject[String]("default") subject.onNext("zero") subject.onNext("one") subject.onError(new RuntimeException("error")) subject.subscribe(observer)
Example: -
object
PublishSubject
Subject that, once an
Observerhas subscribed, emits all subsequently observed items to the subscriber.Subject that, once an
Observerhas subscribed, emits all subsequently observed items to the subscriber.
val subject = PublishSubject[String]() // observer1 will receive all onNext and onCompleted events subject.subscribe(observer1) subject.onNext("one") subject.onNext("two") // observer2 will only receive "three" and onCompleted subject.subscribe(observer2) subject.onNext("three") subject.onCompleted()
Example: -
object
ReplaySubject
Subject that buffers all items it observes and replays them to any
Observerthat subscribes.Subject that buffers all items it observes and replays them to any
Observerthat subscribes.
val subject = ReplaySubject[String]() subject.onNext("one") subject.onNext("two") subject.onNext("three") subject.onCompleted() // both of the following will get the onNext/onCompleted calls from above subject.subscribe(observer1) subject.subscribe(observer2)
Example: -
object
SerializedSubject
Wraps a Subject to ensure that the resulting Subject is chronologically well-behaved.
Wraps a Subject to ensure that the resulting Subject is chronologically well-behaved.
A well-behaved Subject does not interleave its invocations of the onNext, onCompleted, and onError methods of its rx.lang.scala.Subjects; it invokes
onCompletedoronErroronly once; and it never invokesonNextafter invoking eitheronCompletedoronError.SerializedSubject enforces this, and the Subject it returns invokes
onNextandonCompletedoronErrorsynchronously on the wrapped Subject. -
object
TestSubject
A variety of Subject that is useful for testing purposes.
A variety of Subject that is useful for testing purposes. It operates on a
TestSchedulerand allows you to precisely time emissions and notifications to the Subject's subscribers. -
object
UnicastSubject
EXPERIMENTAL A
Subjectvariant which buffers events until a singleSubscriberarrives and replays them to it and potentially switches to direct delivery once theSubscribercaught up and requested an unlimited amount.EXPERIMENTAL A
Subjectvariant which buffers events until a singleSubscriberarrives and replays them to it and potentially switches to direct delivery once theSubscribercaught up and requested an unlimited amount. In this case, the buffered values are no longer retained. If theSubscriberrequests a limited amount, queueing is involved and only those values are retained which weren't requested by theSubscriberat that time.- Annotations
- @Experimental()