All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.katanox.tabour.Retry.kt Maven / Gradle / Ivy

There is a newer version: 1.0
Show newest version
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)
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy