In addition to what Simon Bazle said, here is a short version with a linear digression:
.retryWhen(notification -> notification .zipWith(Observable.range(1, 5), Tuple::create) .flatMap(att -> att.value2() == 3 ? Observable.error(att.value1()) : Observable.timer(att.value2(), TimeUnit.SECONDS) ) )
Note that the “att” here is a tuple that consists of both throwable and the number of repetitions, so you can very accurately implement the return logic based on these two parameters.
If you want to know even more, you can look into the stable document that I am writing now: https://gist.github.com/daschl/db9fcc9d2b932115b679#retry-with-delay
daschl
source share