
com.github.insanusmokrassar.AutoPostTelegramBot.utils.flow.CollectWithErrors.kt Maven / Gradle / Ivy
package com.github.insanusmokrassar.AutoPostTelegramBot.utils.flow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
suspend fun Flow.collectWithErrors(
onError: (suspend (value: T, throwable: Throwable) -> Unit)? = null,
action: suspend (value: T) -> Unit
) = collect {
try {
action(it)
} catch (e: Throwable) {
onError ?.invoke(it, e)
}
}
suspend inline fun Flow.collectWithErrors(noinline action: suspend (value: T) -> Unit) = collectWithErrors(
null,
action
)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy