In RXJava, I have a 2 observables which are responses from 2 downstream calls.One downstream call is a long poll call, other is a short one and returns right away. I am using the Observable.zip to combine the responses of both the responses.The below code works fine.
Observable
.zip(observable1, observable2)
.flatMap(update -> foo(update));
Now what I want to implement is that if the output of the short downstream call (observable1) does not content a specific value, then skip the zip i.e dont wait for the output of the longer downstream call (observable2). I tried to implement it in the below way, but if the condition is true it doesn't zip with the observable2, but it does not even emit observable1 response.
Observable finalresponse = observable1
.takeWhile(obsResponse1 -> checkIfValueExist(obsResponse1))
.zipWith(observable2, (observable1, observable2) -> execute(observable1, observable2))
.flatMap(update -> main.execute(update));