June 2015
Intermediate to advanced
182 pages
3h 56m
English
The Subject instances are both Observable instances and Observer instances. Like Observable instances, they can have multiple Observer instances, receiving the same notifications. That's why they can be used to turn cold Observable instances into hot ones. Like Observer instances, they give us access to their onNext(), onError(), or onCompleted() methods.
Let's look at an implementation of the preceding hot interval examples, using a Subject instance:
Observable<Long> interval = Observable.interval(100L, TimeUnit.MILLISECONDS); // (1)
Subject<Long, Long> publishSubject = PublishSubject.create(); // (2) interval.subscribe(publishSubject); // (3) Subscription sub1 = subscribePrint(publishSubject, "First"); Subscription sub2 = ...Read now
Unlock full access