June 2017
Intermediate to advanced
400 pages
8h 44m
English
There are a few other flavors of Subjects. Aside from the commonly used PublishSubject, there is also BehaviorSubject. It behaves almost the same way as PublishSubject, but it will replay the last emitted item to each new Observer downstream. This is somewhat like putting replay(1).autoConnect() after a PublishSubject, but it consolidates these operations into a single optimized Subject implementation that subscribes eagerly to the source:
import io.reactivex.subjects.BehaviorSubject;import io.reactivex.subjects.Subject;public class Launcher { public static void main(String[] args) { Subject<String> subject = BehaviorSubject.create(); subject.subscribe(s -> System.out.println("Observer 1: " + s)); subject.onNext("Alpha"); ...
Read now
Unlock full access