PublishSubject
There are a couple of extensions of the Subject abstract class that extend the Observable abstract class and implement the Observer interface. This means that you can manually call onNext(), onComplete(), and onError() on a Subject, and it will, in turn, pass those events downstream to the Observer objects that subscribe to it.
The simplest Subject type is PublishSubject, which, like all Subject classes, hotly broadcasts to the Observer objects that subscribe to it. Other Subject types add more behavior, but PublishSubject is the most basic Subject extension.
We can declare a Subject<String>, create an Observer object that maps the String value to its length, and subscribes to it. Then, we can call onNext() on the Subject<String> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access