0

I want to create an observable that emits values every 5 seconds (0s, 5s, 10s, etc) and when I used Observable.interval(5, TimeUnit.SECONDS) there's 5 seconds delay before emitting the very first event and when I googled and tried to use Observable.timer I was confused by its Scheduler scheduler parameter.

My current workaround (after I found the answers to some similar question) is to add .startsWith(0L):

Observable.interval(5, TimeUnit.SECONDS).startsWith(0L)

Is there an operator that accepts delay (or takes 0 by default) and where I can specify an interval?

B. Wasnie
  • 541
  • 1
  • 4
  • 12
  • `Observable.interval()` emits items from `0` and it results in `0 -> 0 -> 1 -> 2...`. Besides that, it looks a bit hacky. – B. Wasnie Aug 23 '19 at 23:38
  • 1
    [I just found this method. Seems like it's what you need.](http://reactivex.io/RxJava/javadoc/io/reactivex/Observable.html#interval-long-long-java.util.concurrent.TimeUnit-) – Sweeper Aug 23 '19 at 23:46

0 Answers0