https://kotlinlang.org logo
#rx
Title
# rx
j

Joan Colmenero

07/27/2020, 12:05 PM
Regarding last question because there are lot of comments and replies... My problem is that I have two repositories one that returns an
Observable
let's call it
repoObservable
and another one that returns a
Single
let's call it
repoSingle
so the thing is, everything before was calling only the
repoObservable
but now we realised that we need that
repoSingle
to be called as well, so what I'm trying to do is to subscribe both in the same
Observable
I've tried to make it with two subscribe and it works, but I wanted to check if it's possible to make it in one observer. What I'm trying is
Copy code
repoObservable.getStream().zipWith(repoSingle.get().toObservable(), (BiFunction<User, User, Object>)(user, user1) -> {
   updateUiWithUser(user); <-- should be from the 
repoObservable.getStream()
   showMessage();
}
but the thing is that it's not called, I wanted to know if is there any possibility to avoid doing something like :
Copy code
repoObservable.observeOn(AndroidSheculers.mainThread())
.subscribe(...)
repoSingle.observeOn(AndroidSchedules.mainThread())
.subscribe(...)
g

gildor

07/27/2020, 12:39 PM
Actually, of those two streams are not related (so you do not do anything with them together in your zip or subscribe, I would rather keep using 2 subscriptions
j

Joan Colmenero

07/27/2020, 3:02 PM
with merge looks working
g

gildor

07/28/2020, 2:42 AM
merge? I just mean that by using something like zip or combineLatest you wait when both are ready and emit only after that. And if you can handle your case with 2 separate subscriptions, it looks that they are not actually connected, so why slowdown one of them, it looks as having 2 subscribe will work just fine
4 Views