Android Rx Kotlin retryWhen问题

Android Rx Kotlin retryWhen问题,android,kotlin,observable,rx-java,Android,Kotlin,Observable,Rx Java,我正在尝试使用.retryWhen()操作在api调用失败时每5秒重试3次。有人能帮我处理这个案子吗?因为我在过去的几个小时里都搞不清楚 .retryWhen { errors -> errors .zipWith(Observable.range(1, 3), { _: Throwable, i: Int -> i }) .flatMap { retryCount: In

我正在尝试使用
.retryWhen()
操作在api调用失败时每5秒重试3次。有人能帮我处理这个案子吗?因为我在过去的几个小时里都搞不清楚

.retryWhen { errors ->
                errors
                    .zipWith(Observable.range(1, 3), { _: Throwable, i: Int -> i })
                    .flatMap { retryCount: Int ->
                        Observable.timer(
                            5.0.pow(retryCount.toDouble()).toLong(),
                            TimeUnit.SECONDS
                        )
                    }
            }
我越来越

None of the following functions can be called with the arguments supplied:
@CheckReturnValue @SchedulerSupport public final fun <U : Any!, R : Any!> zipWith(p0: ((Observer<in Int!>) -> Unit)!, p1: ((Throwable, Int) -> ???)!): Observable<(???..???)>! defined in io.reactivex.Observable
@CheckReturnValue @SchedulerSupport public final fun <U : Any!, R : Any!> zipWith(p0: ObservableSource<out Int!>!, p1: BiFunction<in Throwable!, in Int!, out (???..???)>!): Observable<(???..???)>! defined in io.reactivex.Observable
@CheckReturnValue @SchedulerSupport public final fun <U : Any!, R : Any!> zipWith(p0: (Mutable)Iterable<(???..???)>!, p1: BiFunction<in Throwable!, in (???..???), out (???..???)>!): Observable<(???..???)>! defined in io.reactivex.Observable
@CheckReturnValue @SchedulerSupport public final fun <U : Any!, R : Any!> zipWith(p0: (Mutable)Iterable<Int!>!, p1: ((Throwable, Int) -> ???)!): Observable<(???..???)>! defined in io.reactivex.Observable

我想有人在找类似的东西。我想出了一个对我来说很好的解决办法

.retryWhen { errors ->
                errors.zipWith(Observable.range(1, 3), BiFunction { throwable: Throwable, count: Int -> Pair(throwable, count) })
                    .flatMap { count: Pair<Throwable, Int> ->
                        if (count.second < 3) {
                            Observable.timer(5, TimeUnit.SECONDS)
                        } else {
                           Observable.error(count.first)
                        }
                    }
            }
.retryWhen{errors->
errors.zipWith(Observable.range(1,3),双函数{throwable:throwable,count:Int->Pair(throwable,count)})
.flatMap{count:对->
如果(计数秒<3){
可观察计时器(5,时间单位:秒)
}否则{
可观测误差(计数优先)
}
}
}
it扩展:

import io.reactivex.Observable
import io.reactivex.functions.BiFunction
import java.util.concurrent.TimeUnit

fun <T> Observable<T>.retryWhenError(retryCount: Int, delayInSeconds: Long): Observable<T> {
    return retryWhen { errors ->
        errors.zipWith(
            Observable.range(1, retryCount), BiFunction { throwable: Throwable, count: Int -> Pair(throwable, count) })
            .flatMap { count: Pair<Throwable, Int> ->
                if (count.second < retryCount) {
                    Observable.timer(delayInSeconds, TimeUnit.SECONDS)
                } else {
                    Observable.error(count.first)
                }
            }
    }
}
导入io.reactivex.Observable
导入io.reactivex.functions.BiFunction
导入java.util.concurrent.TimeUnit
有趣的可观察。retryWhenError(retryCount:Int,DelayUnseconds:Long):可观察{
返回retryWhen{errors->
泽普维思酒店(
可观察范围(1,retryCount),双函数{throwable:throwable,count:Int->Pair(throwable,count)}
.flatMap{count:对->
if(count.second
我应该如何自定义您的扩展,使其仅在特定状态(如408或500**)后重试?只需选中throwable exception而不是count。secondimport io.reactivex.Observable import io.reactivex.functions.BiFunction import java.util.concurrent.TimeUnit fun <T> Observable<T>.retryWhenError(retryCount: Int, delayInSeconds: Long): Observable<T> { return retryWhen { errors -> errors.zipWith( Observable.range(1, retryCount), BiFunction { throwable: Throwable, count: Int -> Pair(throwable, count) }) .flatMap { count: Pair<Throwable, Int> -> if (count.second < retryCount) { Observable.timer(delayInSeconds, TimeUnit.SECONDS) } else { Observable.error(count.first) } } } }