Polling with RxJava 2

And how to unit test it

Use cases

Getting user’s status from server so as to “block” the bad ones, checking payment confirmation that takes 2–3 mins

Push notifications have advantages (non-blocking UX)and disadvantages (unreliability, cost e.g.SMS, can get complex quickly). There are times we really wanna do polling

It’s not just about getting data from server, sometimes we want to send server data repeatedly, as long as the app lives, or until user turn off the function e.g. send location to server in a transport app

Notes

Observable.interval(2L, TimeUnit.SECONDS, schedulerProvider.io)... will work

while

Observable.interval(2L, TimeUnit.SECONDS).subscribeOn(schedulerProvider.io) will not!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store