Repeat vs. Retry
Main difference between repeat and retry is event causes a resubscription:
repeat()resubscribes when it receivesonCompleted().retry()resubscribes when it receivesonError().
Key points about repeatWhen and retryWhen:
repeatWhenis identical toretryWhen, only it responds toonCompletedinstead ofonError. The input isObservable<Void>, sinceonCompletedhas no type.- The
notificationHandler(i.e.Func1) is only called once per subscription. This makes sense as you are given anObservable<Throwable>, which can emit any number of errors. - The output
Observablehas to use the inputObservableas its source. You must react to theObservable<Throwable>and emit based on it; you can’t just return a generic stream. - The
Observableinput only triggers on terminal events (onCompletedforrepeatWhen/onErrorforretryWhen). It doesn’t receive any of theonNextnotifications from the source, so you can’t examine the emitted data to determine if you should resubscribe. If you want to do that, you have to add an operator liketakeUntil()to cut off the stream.
Links
https://blog.danlew.net/2016/01/25/rxjavas-repeatwhen-and-retrywhen-explained/
https://android.jlelse.eu/rx-grokking-retrywhen-and-repeatwhen-on-android-development-examples-af5c3ed0872b