Observable.interval () with initialDelay
I have a polling service that is implemented using Observable.interval(POLL_INTERVAL, Seconds)
. This works great, but I would like the first delay to be 0, I mean I would like to start polling right away and then continue polling each POLL_INTERVAL. How is this achievable?
+3
Nima
source
to share
1 answer
RxJava has 3 operators related to synchronization (+1 overload of each):
-
timer(long delay, TimeUnit unit [, Scheduler scheduler])
emits one 0L after delay, -
timer(long initialDelay, long period, TimeUnit unit [, Scheduler scheduler])
emits 0L after an initial delay and continuously increasing values thereafter, -
interval(long interval, TimeUnit unit [, Scheduler scheduler])
emits 0L after interval and 1L, 2L, etc. periodically. This is equivalenttimer(interval, interval, unit)
.
+3
akarnokd
source
to share