File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed
src/main/kotlin/me/proxer/app/util Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -4,18 +4,21 @@ import io.reactivex.Flowable
4
4
import io.reactivex.functions.Function
5
5
import java.util.concurrent.TimeUnit
6
6
7
+ /* *
8
+ * Stolen and adjusted from here: https://stackoverflow.com/a/25292833/4279995
9
+ */
7
10
class RxRetryWithDelay (
8
- private val maxRetries : Int ,
9
- private val retryDelayMillis : Long
11
+ private val maxRetries : Int ,
12
+ private val retryDelayMillis : Long
10
13
) : Function<Flowable<out Throwable>, Flowable<*>> {
11
14
12
15
private var retryCount: Int = 0
13
16
14
17
override fun apply (attempts : Flowable <out Throwable >): Flowable <Any > = attempts
15
- .flatMap { throwable ->
16
- when {
17
- ++ retryCount < maxRetries -> Flowable .timer(retryDelayMillis, TimeUnit .MILLISECONDS )
18
- else -> Flowable .error(throwable)
19
- }
18
+ .flatMap { throwable ->
19
+ when {
20
+ ++ retryCount < maxRetries -> Flowable .timer(retryDelayMillis, TimeUnit .MILLISECONDS )
21
+ else -> Flowable .error(throwable)
20
22
}
23
+ }
21
24
}
You can’t perform that action at this time.
0 commit comments