rxjava: Can I use retry() but with delay?

后端 未结 14 2257
别那么骄傲
别那么骄傲 2020-11-28 18:25

I am using rxjava in my Android app to handle network requests asynchronously. Now I would like to retry a failed network request only after a certain time has passed.

14条回答
  •  攒了一身酷
    2020-11-28 18:55

    Inspired by Paul's answer, and if you are not concerned with retryWhen problems stated by Abhijit Sarkar, the simplest way to delay resubscription with rxJava2 unconditionnaly is :

    source.retryWhen(throwables -> throwables.delay(1, TimeUnit.SECONDS))
    

    You may want to see more samples and explanations on retryWhen and repeatWhen.

提交回复
热议问题