Reputation: 169
Given I subscribe to 2 different Observables and I want get both of them on onNext after do some operations to them
let's say I have 2 Observables
Observable<List<String>> childName = Observable.from(children)... some operations
Observable<List<String>> teacherName = Observable.from(teachers)... some operations
how do I get both of them on my subscribe?
subscribe(
onNext(List<String> childName, List<String> className)
so that I can pass both of them in my listener in that manner.
I don't want to combine them, I just want when after the operations are finished, get both of them and pass it on my subscriptions
Upvotes: 4
Views: 120
Reputation: 11058
hacky but simple
Observable.zip(childName, teacherName, (childList, teachersList) -> {
// handle childList & teachersList
return Observable.empty();
}).subscribe(o -> {}, error -> {
//handle errors
});
Upvotes: 0
Reputation: 69997
You can zip
their values into a Pair
:
Observable.zip(childName, className,
(a, b) -> Pair.of(a, b))
.subscribe((Pair<List<String>, List<String>> pair) -> {
// do something with pair.first and pair.second
}, Throwable::printStackTrace);
Upvotes: 3