Retry extension function in coroutine #4502
Closed
shashwathkamath
started this conversation in
Ideas
Replies: 2 comments 1 reply
-
Hi Shashwath, Sounds like you need ktor-client This use-case is outside of the scope of the coroutine library, as it also requires the library to incorporate knowledge about web services. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Related issues/discussions: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Idea: Handling transient failures (e.g., network timeouts) in suspending functions often requires custom retry logic, which is repetitive and error-prone. A simple, reusable retry mechanism with exponential backoff would improve developer experience in
kotlinx.coroutines
.Proposed API:
suspend fun retryWithBackoff(
maxAttempts: Int = 3,
initialDelay: Duration = 500.milliseconds,
maxDelay: Duration = 5000.milliseconds,
backoffFactor: Double = 2.0,
predicate: (Throwable) -> Boolean = { true },
block: suspend () -> T
): Result
val result = retryWithBackoff { fetchDataFromServer() }
Beta Was this translation helpful? Give feedback.
All reactions