question on combining streams: i have a state obse...
# rx
d
question on combining streams: i have a state observable which can emit random states. the first emission can take up to 10-15 seconds. also, i want to display a countdown for one of the state’s properties (
timeLeft
in seconds). my first approach was
combineLatest(state, Observable.interval(1, TimeUnit.SECONDS))
but the timer seems to start before i even receive a state, thus my countdown is wrong. my next approach would be
state.switchMap { state -> Observable.interval(1, TimeUnit.SECONDS). map { elapsedTime -> state.timeLeft - elapsedTime}}
- is there a “better” approach to this?
j
won't that work?
combineLatest(state.startWith(dummyState), Observable.interval(1, TimeUnit.SECONDS))
?
d
but i dont have a dummy state available, and once the “real state” comes the interval will already have the same amount of time
elapsed