CoroutineScope#safeActor

This commit is contained in:
InsanusMokrassar 2020-11-02 21:32:04 +06:00
parent 6f5c6e5ebe
commit dccb479c3c
2 changed files with 13 additions and 0 deletions

View File

@ -4,6 +4,7 @@
* `Coroutines` * `Coroutines`
* Function `safelyWithoutExceptions` * Function `safelyWithoutExceptions`
* Extension `CoroutineScope#safeActor`
## 0.2.4 ## 0.2.4

View File

@ -17,3 +17,15 @@ fun <T> CoroutineScope.actor(
return channel return channel
} }
inline fun <T> CoroutineScope.safeActor(
channelCapacity: Int = Channel.UNLIMITED,
noinline onException: ExceptionHandler<Unit> = {},
crossinline block: suspend (T) -> Unit
): Channel<T> = actor(
channelCapacity
) {
safely(onException) {
block(it)
}
}