Skip to content

Commit 4a71f92

Browse files
committed
Add attribution for RetryWithDelay and fix code style
1 parent 6afa3da commit 4a71f92

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/main/kotlin/me/proxer/app/util/RxRetryWithDelay.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ import io.reactivex.Flowable
44
import io.reactivex.functions.Function
55
import java.util.concurrent.TimeUnit
66

7+
/**
8+
* Stolen and adjusted from here: https://stackoverflow.com/a/25292833/4279995
9+
*/
710
class RxRetryWithDelay(
8-
private val maxRetries: Int,
9-
private val retryDelayMillis: Long
11+
private val maxRetries: Int,
12+
private val retryDelayMillis: Long
1013
) : Function<Flowable<out Throwable>, Flowable<*>> {
1114

1215
private var retryCount: Int = 0
1316

1417
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)
2022
}
23+
}
2124
}

0 commit comments

Comments
 (0)