ericn
ericn

Reputation: 13103

RxJava 2 how to do something immediately and repeat every X minutes

I know the delay() and repeat() operator and have read this question.

However, I want the first event to be fired immediately, not wait for X minutes.
It would be weird when user clicks a button and have to wait for X minutes to see the results right?

I want to do something like doSomeTask().nowAndEveryXMinAfter().

doSomeTask:

Observable<Integer> doSomeTask() {
}

Upvotes: 0

Views: 1392

Answers (1)

Alex
Alex

Reputation: 3013

I think you are looking for the interval operator:

Observable.interval(0, 1, TimeUnit.MINUTES)

Where you can specify the initial delay, and then emit every x minutes. I'm not sure what exactly you want to do, but you can for example concat this after your action if that's an observable.

Upvotes: 3

Related Questions