retryWhen(new Function<Flowable<Throwable>, Publisher<?>>() {
@Override
public Publisher<?> apply(Flowable<Throwable> errors) throws Throwable {
return errors
.zipWith(Flowable.range(1, 10), new BiFunction<Throwable, Integer, Integer>() {
@Override
public Integer apply(Throwable error, Integer retryCount) throws Throwable {
if (retryCount >= 10) {
Log.d("testhyy","Retry limit reached");
throw new RuntimeException("Retry limit reached");
}
return retryCount;
}
})
.flatMap(new Function<Integer, Publisher<?>>() {
@Override
public Publisher<?> apply(Integer retryCount) throws Throwable {
count++;
Log.d("testhyy","Retrying... Attempt " + retryCount);
return Flowable.timer(1, TimeUnit.SECONDS);
}
});
}
})
rxjava http接口请求重试
最新推荐文章于 2024-07-25 17:33:18 发布