I need to run 2 JOB at a specific interval of 4,8,12,16... second and another one is 5,9,13,17...second.
I have used Interval operator in RxJava. Job B needs to run after Job A. Job B should sleep when Job A is running and vice versa. Till now the code looks below
var compositeDisposable = CompositeDisposable()
compositeDisposable.add(Observable.interval(0, recordIntervalPeriod, TimeUnit.MILLISECONDS)
.serialize()
.subscribe {
JobA()
})
compositeDisposable.add(Observable.interval(0, recorderStopIntervalStartTime, TimeUnit.MILLISECONDS)
.serialize()
.subscribe {
JobB()
})
Need help in following
1. Best way to achieve the above using RxJava
2. Run JobA for 4 second then run JobB for 4 second and repeat the process again.
I would suggest you use a single job that runs every second, and decide each time which job to call based on the counter value:
If you still want to use two observables, I think this will work too:
Disclaimer: I haven't used RxJava a lot.