February 2020
Intermediate to advanced
412 pages
9h 36m
English
The ReplaySubject class behaves similar to PublishSubject followed by a cache() operator. It immediately captures emissions regardless of the presence of a downstream Observer and optimizes the caching to occur inside the Subject itself. Here is an example:
import io.reactivex.rxjava3.subjects.ReplaySubject;import io.reactivex.rxjava3.subjects.Subject;public class Ch5_19 { public static void main(String[] args) { Subject<String> subject = ReplaySubject.create(); subject.subscribe(s -> System.out.println("Observer 1: " + s)); subject.onNext("Alpha"); subject.onNext("Beta"); subject.onNext("Gamma"); subject.onComplete(); subject.subscribe(s -> System.out.println("Observer 2: " + s)); }}
The output obtained is as follows:
Observer ...
Read now
Unlock full access