Hi, I'm using Retrofit 1.9.0 and have an API like this:
interface Api {
@GET("/foo")
public Observable<Foo> getFoo();
I want to use Observable<Foo> in two rx java chains (i.e. combineLatest()) like this (pseudo code):
Observable<Foo> fooObservable = api.getFoo();
// Nonblocking
Observable.combineLatest( aObservable, fooObservable, ... ).subscribe( ... );
// Non blocking
Observable.combineLatest( bObservable, fooObservable, ... ).subscribe( ... );
I would expect that both combineLatest() chains would receive the same single data from fooObservable since both are observing the same fooObservable (as long as not onCompleted()). But it seems that the request to get foo is executed twice for each combineLatest() chain.
Is that the desired behaviour? I haven't tried Retrofit 2.0-SNAPSHOT yet, is that behaviour going to change in Retrofit 2.0?
Every subscription creates its own request. In your example you have two functions which subscribe, hence two requests. This is a property of _all_ cold observables regardless of what library they come from and that behavior will not be changing.
If you want to create only a single request, look into the refCount(), share(), and publish()/connect() operators. Personally I'm a fan of share(). In this case, append it to the first line in your code block and things will magically start to work!
Oh... right I had an error in reasoning in combination with sqlbrite!
sorry for bothering you.
Thanks for clarification!
Most helpful comment
Every subscription creates its own request. In your example you have two functions which subscribe, hence two requests. This is a property of _all_ cold observables regardless of what library they come from and that behavior will not be changing.
If you want to create only a single request, look into the
refCount(),share(), andpublish()/connect()operators. Personally I'm a fan ofshare(). In this case, append it to the first line in your code block and things will magically start to work!