mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-17 13:53:49 +00:00
CoroutineScope with safely handler parameter
This commit is contained in:
parent
bd9b0d16ab
commit
eed7cfdc42
@ -5,6 +5,8 @@
|
||||
* `Versions`:
|
||||
* `Coroutines`: `1.5.1` -> `1.5.2`
|
||||
* `Klock`: `2.3.4` -> `2.4.1`
|
||||
* `Coroutines`:
|
||||
* New function `CoroutineScope` with safely exceptions handler as second parameter
|
||||
|
||||
## 0.5.23
|
||||
|
||||
|
@ -39,9 +39,11 @@ object ContextSafelyExceptionHandlerKey : CoroutineContext.Key<ContextSafelyExce
|
||||
*/
|
||||
class ContextSafelyExceptionHandler(
|
||||
val handler: ExceptionHandler<Unit>
|
||||
) : CoroutineContext.Element {
|
||||
) : CoroutineContext.Element, CoroutineExceptionHandler {
|
||||
override val key: CoroutineContext.Key<*>
|
||||
get() = ContextSafelyExceptionHandlerKey
|
||||
|
||||
override fun handleException(context: CoroutineContext, exception: Throwable) = handler(exception)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -147,3 +149,10 @@ suspend inline fun <T> runCatchingSafelyWithoutExceptions(
|
||||
): Result<T?> = runCatching {
|
||||
safelyWithoutExceptions(onException, block)
|
||||
}
|
||||
|
||||
suspend inline fun CoroutineScope(
|
||||
context: CoroutineContext,
|
||||
defaultExceptionsHandler: ExceptionHandler<Unit>
|
||||
) = CoroutineScope(
|
||||
context + ContextSafelyExceptionHandler(defaultExceptionsHandler)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user