Reactive programming – creating behaviorsubject from observable
•
Java
Suppose I have an observable a that gets data from the network and sends it. If I subscribe to this observable every time I try to request data from the network
I want to create a behaviorsubject and connect it to observablea so that any other thread / object will subscribe to behaviorsubject to get the latest issued data
So far, I can't manage the code I can't create empty BehaviorSubject and call them in observableA, because they are not related to each other. I can't subscribe to observablea and use behaviorsubject as an observer. How can any idea implement it? Or even better?
Solution
You can use multicast For example,
Observable<String> o = ...; ConnectableObservable<String> co = o.multicast(BehaviorSubject.<String> create()); co.connect(); co.subscribe(...); co.subscribe(...); co.subscribe(...);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码