
Adds concurrent mapAsync, pairwise emissions, flow racing, exponential-backoff retries, timeout-or-null, and default/fallback helpers for building composable, resilient asynchronous streams with concise APIs.
Library that extends standard library of Kotlin's coroutines with missing functions.
Detailed documentation for all functions
Ensure you have MavenCentral in your settings.gradle.kts:
repositories {
...
mavenCentral()
}
Add dependency in build.gradle.kts in project/subproject where helper functions are needed:
implementation("io.github.rain991:coroutines-extensions:1.0.0")
| Name | Summary |
|---|---|
| mapAsync |
suspend fun <T, R> Iterable<T>.mapAsync(transform: suspend (T) -> R): List<R>Transforms all elements of the iterable concurrently. |
| pairwise |
fun <T> Flow<T>.pairwise(): Flow<Pair<T, T>>For each emission after the first, emits a Pair(previous, current). |
| raceWith |
suspend fun <T> Flow<T>.raceWith(other: Flow<T>): TReturns the value from the flow that emits first. |
| retryWithExponentialBackoff |
fun <T> Flow<T>.retryWithExponentialBackoff(maxAttempts: Int, initialDelay: Duration, multiplier: Double = 2.0, retryOn: (Throwable) -> Boolean = { true }): Flow<T>Retries the flow when it fails, increasing the delay between retries exponentially. |
| timeoutOrNull |
fun <T> Flow<T>.timeoutOrNull(timeout: Duration): Flow<T?>Emits the first value from the upstream flow or null if no value is emitted within the given timeout. |
| withDefault |
fun <T> Flow<T>.withDefault(default: T): Flow<T>Emits the provided default value if the upstream flow is empty.fun <T> Flow<T>.withDefault(default: T, shouldDefault: (Throwable) -> Boolean): Flow<T>Emits the provided default value if the upstream flow is empty or if shouldDefault returns true for an exception. |
| withFallback |
fun <T> Flow<T>.withFallback(fallbackWhen: (Throwable) -> Boolean = { true }, fallback: () -> Flow<T>): Flow<T>Emits from the upstream flow and switches to the fallback flow in case of an exception. |
Library that extends standard library of Kotlin's coroutines with missing functions.
Detailed documentation for all functions
Ensure you have MavenCentral in your settings.gradle.kts:
repositories {
...
mavenCentral()
}
Add dependency in build.gradle.kts in project/subproject where helper functions are needed:
implementation("io.github.rain991:coroutines-extensions:1.0.0")
| Name | Summary |
|---|---|
| mapAsync |
suspend fun <T, R> Iterable<T>.mapAsync(transform: suspend (T) -> R): List<R>Transforms all elements of the iterable concurrently. |
| pairwise |
fun <T> Flow<T>.pairwise(): Flow<Pair<T, T>>For each emission after the first, emits a Pair(previous, current). |
| raceWith |
suspend fun <T> Flow<T>.raceWith(other: Flow<T>): TReturns the value from the flow that emits first. |
| retryWithExponentialBackoff |
fun <T> Flow<T>.retryWithExponentialBackoff(maxAttempts: Int, initialDelay: Duration, multiplier: Double = 2.0, retryOn: (Throwable) -> Boolean = { true }): Flow<T>Retries the flow when it fails, increasing the delay between retries exponentially. |
| timeoutOrNull |
fun <T> Flow<T>.timeoutOrNull(timeout: Duration): Flow<T?>Emits the first value from the upstream flow or null if no value is emitted within the given timeout. |
| withDefault |
fun <T> Flow<T>.withDefault(default: T): Flow<T>Emits the provided default value if the upstream flow is empty.fun <T> Flow<T>.withDefault(default: T, shouldDefault: (Throwable) -> Boolean): Flow<T>Emits the provided default value if the upstream flow is empty or if shouldDefault returns true for an exception. |
| withFallback |
fun <T> Flow<T>.withFallback(fallbackWhen: (Throwable) -> Boolean = { true }, fallback: () -> Flow<T>): Flow<T>Emits from the upstream flow and switches to the fallback flow in case of an exception. |