Reputation: 6563
I have a polling service which is implemented using Observable.interval(POLL_INTERVAL, Seconds)
. This works fine but I would like the first delay to be 0, I mean I would like to start the poll immediately and then continue to poll every POLL_INTERVAL. How is this achievable?
Upvotes: 4
Views: 1746
Reputation: 69997
RxJava has 3 timing related operators (+1 overload each):
timer(long delay, TimeUnit unit [, Scheduler scheduler])
emits a single 0L after the delay,timer(long initialDelay, long period, TimeUnit unit [, Scheduler scheduler])
emits a 0L after the initial delay and ever incrementing values periodically after that,interval(long interval, TimeUnit unit [, Scheduler scheduler])
emits 0L after the interval and 1L, 2L, etc. periodically. It is equivalent to timer(interval, interval, unit)
.Upvotes: 4