diff --git a/CHANGELOG.md b/CHANGELOG.md index a99129f2557..c8380af1456 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * `Coroutines` * Function `safelyWithoutExceptions` + * Extension `CoroutineScope#safeActor` ## 0.2.4 diff --git a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/Actor.kt b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/Actor.kt index 310d67c32f1..dbfc4b45254 100644 --- a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/Actor.kt +++ b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/Actor.kt @@ -17,3 +17,15 @@ fun CoroutineScope.actor( return channel } +inline fun CoroutineScope.safeActor( + channelCapacity: Int = Channel.UNLIMITED, + noinline onException: ExceptionHandler = {}, + crossinline block: suspend (T) -> Unit +): Channel = actor( + channelCapacity +) { + safely(onException) { + block(it) + } +} +