Hello how do I subscribe to an `Observable` and `...
# rx
j
Hello how do I subscribe to an
Observable
and
Single
at the same time? I have this
Copy code
Observable.zip(repo1.getStream(), repoSingle.getStream().toObservable(), (repo1, repo2) -> repo1)
But it's not calling, the thing is that I'd like to execute both and subscribe to both in the same
subscribe
it works if I create two separate subscribe though. Also I need to use the result of the
repo1.getStream()
to make some calls from the result like if is returning an user I'd like to do user -> user.getFoo(). Thanks
g
But do you understand that if you combine Observable and single, this observablew finish when single success?
j
Yes I guess this is the problem why is not working..
g
so it’s expected
j
I read about
doOnDispose()
also but don't know how to make it work
g
why do you need doOnDispose?
what is you expected semantics?
j
Because when one finishes it calls the doOnDispose as far as I read on the documentation
g
yes
but not when it finishes
but when it disposed
j
well the thing is I'd like to avoid this
this observablew finish when single success?
And wait until both are done
g
to subscribe on finish use doFinally
And wait until both are done
But this code works like this
j
If it's possible because if I create two subscribe it works but looks ugly to me
g
so after your single is finish it’s fine to stop observing repo1?
zip waits when both streams emit at least 1 value
but it will be completed if one of them complete
so it probabably what you want, but if you need only 1 value, I would recommend instead Single.zip
j
The thing is normally I was using observable but then I realized that I need that Single to make it work
g
It would be a bit more clear semantically and it checks that at least 1 value is emmitted
j
Because more values can be emited (by the observable) single is fire and forget
But I need to call it to update some UI
g
anyway, I would recommend to write some sample and demonstrate what doesn’t work for you
j
The other needs to be there
g
because it’s not clear what semantics you excpect
j
Ok the thing is, this Observable (repo1) doesn't need to stop, but this Single(repo2) is only to make sure some UI is updated, so I thought about making a Zip and then just use the result of the repo1(Observable) and forget about repo2(Single)
What I had before is only this Observable and I was using the result (user) and updating UI with that user, now, I need to call another repository (Single) but it's doing the changes internally so it's like I don't need to act with it
g
Use combineLatest instead of zip, it will not stop observable when single success, it will emit both values every time when observable emits
j
I'll try thanks
But I have to put it with specific order?
g
Specific order?
Ahhh, I got it, it will just change order of params in lambda, same as with zip
j
So the syntax is Observable.combineLatest(repo1.getStream, repo2.getInfo)?
g
There are many different overloads, check javadoc
You also should provide combining lambda as latest argument,same as for zip
j
I think I got it, let me test it and I'll come back 🙂
Thanks