retry With Constant Delay
suspend fun <R> retryWithConstantDelay(retries: Long = 3, delay: Duration = 1.seconds, block: suspend () -> R): R(source)
Executes a suspend operation with retry using constant delay between attempts.
This is useful when you want predictable retry intervals, such as polling an API or waiting for a resource to become available.
Return
The result of the successful execution
Parameters
retries
The maximum number of retry attempts (defaults to 3)
delay
The fixed delay between retry attempts (defaults to 1 second)
block
The suspend operation to execute
Type Parameters
R
The return type of the suspend operation
Throws
if all retry attempts fail
Example usage:
val status = retryWithConstantDelay(retries = 10, delay = 500.milliseconds) {
healthService.checkStatus()
}Content copied to clipboard