com.katanox.tabour.Retry.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
A Kotlin library to consume and produce SQS messages
package com.katanox.tabour
internal suspend inline fun retry(
repeatTimes: Int,
onError: (Throwable) -> Unit,
crossinline f: suspend () -> Unit
) {
var tries = 0
while (tries < repeatTimes) {
try {
f()
break
} catch (e: Throwable) {
tries++
if (tries == repeatTimes) {
onError(e)
}
}
}
}