1
Observable<List<Stop>> zippedObservable = Observable.zip(observableList, objects -> {
    List<Stop> stopList = Collections.emptyList();
    for (Object obj : objects) {
        stopList.add((Stop) obj);
    }
    return stopList;
});

I have the zippedObservable variable which was zipped by multiple observables.

disposable.add(zippedObservable.observeOn(AndroidSchedulers.mainThread())
    .subscribeWith(new DisposableObserver<List<Stop>>() {
    // onNext, onComplete, onError omitted
}));

This function emits the items (zipped stop list) successfully, but I'd like to emit these items every minute. I assumed that interval operator would be perfect for this case, but I couldn't figure out how to mix both zip and interval functionalities.

This is what I tried

zippedObservale.interval() // cannot call interval operator here.
Observable.zip(...).interval() // cannot call interval operator here too.

I am looking for someone to explain how to mix these two operators so that I can emit the items every minute. Thank you.

kimchistudent
  • 97
  • 2
  • 7

1 Answers1

1

interval is a static method that creates an Observable<Long> that emits a Long at a given period or interval.

To achieve what you describe, you need to use one such Observable to pace your zipped Observable:

Observable<List<Stop>> zipped = ...;
Observable<Long> interval = Observable.interval(...);
Observable<List<Stop>> everyMinute = zipped.sample(interval);

In that case, it will simply emit at most one result of zipped every minute, dis-regarding whatever else zipped is emitting. I'm not sure that's what you want.

If you want to simply re-emit the same value over and over, you might want to add a repeat() in between.

njzk2
  • 38,969
  • 7
  • 69
  • 107