RxJava2 timer and combLatest

new to RxJava2 I'm having problems with timer

and combineLatest

for example:

Observable.combineLatest(
  Observable.timer(5, TimeUnit.SECONDS).map { TimedData(it) },
  locationDataSource.listen(),
  sensorDataSource.listen().
  Function3 { timedData, location, sensorEvent -> Combined(timedData, location, sensorEvent) }
).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe {
  Log.d(TAG, "Timer -> " + it.timedData)
}

      

What happens is it timedData

only updates once, then it never fires again, all other observables start updating. I found https://github.com/ReactiveX/RxJava/issues/1717 , but from 2014, so I think it already solved it.

Is this still due to BackPressure?

+3


source to share


1 answer


It works as designed. Observable.timer

assigns some task to run once. If you want to get something done periodically, try interval

instead timer

.



Observable.interval(0,5, TimeUnit.SECONDS);

      

+2


source







All Articles