Search code examples
rx-javarx-androidrx-java2reactivex

Combining 2 Observables only if the first one fires


I'm quite new to Rx and I have a situation that I don't find anything about (or maybe I don't ask the right question). I have an observable that should trigger a specific method. However to call that method I need the value from a second observable (which will btw have that value always before the first one). How do I combine the two so that the method only gets called when the first observable fires? It's like with combineLatest, but that one fires if either of the Observables fire. Br, Daniel


Solution

  • If I understand the question correctly you can use the withLatestFrom operator so that the combination and subsequent emission is gated by the first observable.

    It is listed on the same page with combine latest: http://reactivex.io/documentation/operators/combinelatest.html