PublishSubject
There are a couple implementations of Subject, which is an abstract type that implements both Observable and Observer. This means that you can manually call onNext(), onComplete(), and onError() on a Subject, and it will, in turn, pass those events downstream toward its Observers.
The simplest Subject type is the PublishSubject, which, like all Subjects, hotly broadcasts to its downstream Observers. Other Subject types add more behaviors, but PublishSubject is the "vanilla" type, if you will.
We can declare a Subject<String>, create an Observer that maps its lengths and subscribes to it, and then call onNext() to pass three strings. We can also call onComplete() to communicate that no more events will be passed through this ...
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