retryWithBackoff

fun <T> Flow<T>.retryWithBackoff(retries: Long = 3, base: Duration = 200.milliseconds, factor: Double = 2.0, jitterFactor: Double = 0.1, retryIf: (Throwable) -> Boolean = { it !is CancellationException }): Flow<T>(source)

Retries collection of this Flow using exponential backoff with jitter, mirroring retryWithExponentialBackoff but for a whole flow instead of a single suspend call.

Parameters

retries

maximum number of retry attempts after the initial collection

base

base delay for exponential backoff

factor

exponential growth factor

jitterFactor

randomization factor applied to each computed delay (0.0 disables jitter)

retryIf

predicate deciding whether a given exception should trigger a retry