Package-level declarations

Types

Link copied to clipboard
class RetryPolicy(val maxAttempts: Int = DEFAULT_MAX_ATTEMPTS, val initialBackoff: Duration = DEFAULT_INITIAL_BACKOFF, val maxBackoff: Duration = DEFAULT_MAX_BACKOFF, val jitterFactor: Double = DEFAULT_JITTER_FACTOR, val shouldRetry: (Exception) -> Boolean = { true })

Policy for retryWithBackoff.

Functions

Link copied to clipboard
inline fun <T> Result<T>.getOrElseCancellable(onFailure: (Throwable) -> T): T

Like Result.getOrElse, but rethrows CancellationException if present in the failure.

Link copied to clipboard
inline fun <T> Result<T>.onFailureExceptCancellation(action: (Throwable) -> Unit): Result<T>

Handles non-cancellation failures; rethrows CancellationException so the coroutine can cancel.

Link copied to clipboard
inline fun <E : Throwable, T> Result<T>.onFailureOrRethrow(action: (Throwable) -> Unit): Result<T>

Runs action on failure unless the failure is of type E, in which case it is rethrown.

Link copied to clipboard

If this Result is a failure caused by CancellationException, rethrows it; otherwise returns this.

Link copied to clipboard
suspend fun <T> retryWithBackoff(policy: RetryPolicy = RetryPolicy.DEFAULT, random: Random = Random.Default, block: suspend (attempt: Int) -> T): T

Runs block, retrying on failure with exponential backoff and optional jitter.

Link copied to clipboard
inline fun <T> runCatchingCancellable(block: () -> T): Result<T>

Like runCatching, but rethrows CancellationException so structured concurrency is preserved.

Link copied to clipboard
inline suspend fun <T> suspendRunCatchingCancellable(block: suspend () -> T): Result<T>

Suspend variant of runCatchingCancellable. Use instead of runCatching around suspend work.