RxJava:下次如何重试?

时间:2016-10-29 14:27:56

标签: java rx-java

我知道:

  • retryWhen(...)允许我们重试错误

  • repeatWhen(...)允许重试完整

是否有这样的运营商:

    return Observable.just(isUpdating)
            .repeatWhenOnNext(isUpdating -> { 
                if(isUpdating) {
                    return Observable.timer(2, TimeUnit.SECONDS); // repeat after two seconds
                } else {
                    return Observable.just(isUpdating); // flow down to concatMap
                }
            })
            .concatMap(o -> doSomeWorkONLYWhenIsNotUpdating());

1 个答案:

答案 0 :(得分:1)

嗯......不,但也许会这样做:

return Observable
    .interval(0, 2, TimeUnit.SECONDS)
    .filter(dummy -> !isUpdating)
    .take(1)
    .flatM(dummy -> doSomeWorkONLYWhenIsNotUpdating());