Reputation: 6807
Lets say I want to make a network call and use a rx.Single as I expect just a single value.
How can I apply something like replay().autoConnect()
so the network call does not occur multiple times when I'm subscribing from multiple sources?
Should I use toObservable().replay().autoConnect()
?
I assume there is a reason that the whole publish()
ConnectableObservable
chain is left out?
edit: My question is not about how to convert it to a regular observable. My question is how to continue using the rx.Single the whole way down.
Upvotes: 3
Views: 83
Reputation: 16152
If you convert it to an Observable
, use .cache()
to limit the number of connections to one.
Upvotes: 2
Reputation: 11515
In order to use Observable
method, you'll have to transform your Single
to an Observable
using toObservable
method.
Observable<Object> obs = yourSingle.toObservable();
obs.replay().autoConnect().subscribre();
Upvotes: 0