February 2020
Intermediate to advanced
412 pages
9h 36m
English
There are a few other flavors of a Subject. One of them is the BehaviorSubject class. It behaves almost the same way as PublishSubject, but it also replays the last emitted item to each new Observer downstream. This is somewhat like putting replay(1).autoConnect() after PublishSubject, but it consolidates these operations into a single optimized Subject implementation that subscribes eagerly to the source, as demonstrated by the following example:
import io.reactivex.rxjava3.subjects.BehaviorSubject;import io.reactivex.rxjava3.subjects.Subject;public class Ch5_18 { public static void main(String[] args) { Subject<String> subject = BehaviorSubject.create(); subject.subscribe(s -> System.out.println("Observer 1: " + s)); subject.onNext( ...
Read now
Unlock full access