Merge branch 'master' into 0.25.0

This commit is contained in:
2025-03-03 19:41:13 +06:00

View File

@@ -1,25 +1,20 @@
package dev.inmo.micro_utils.coroutines package dev.inmo.micro_utils.coroutines
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.test.runTest
import kotlin.test.Test import kotlin.test.Test
class HandleSafelyCoroutineContextTest { class HandleSafelyCoroutineContextTest {
@Test @Test
fun testHandleSafelyCoroutineContext() { fun testHandleSafelyCoroutineContext() = runTest {
val scope = CoroutineScope(Dispatchers.Default) val scope = this
var contextHandlerHappen = false var contextHandlerHappen = false
var localHandlerHappen = false var localHandlerHappen = false
var defaultHandlerHappen = false
defaultSafelyExceptionHandler = {
defaultHandlerHappen = true
throw it
}
val contextHandler: ExceptionHandler<Unit> = {
contextHandlerHappen = true
}
val checkJob = scope.launch { val checkJob = scope.launch {
safelyWithContextExceptionHandler(contextHandler) { runCatchingLogging ({
safely( contextHandlerHappen = true
}) {
runCatchingLogging (
{ {
localHandlerHappen = true localHandlerHappen = true
} }
@@ -29,10 +24,8 @@ class HandleSafelyCoroutineContextTest {
println(coroutineContext) println(coroutineContext)
error("That must happen too:)") error("That must happen too:)")
} }
} }.join()
launchSynchronously { checkJob.join() }
assert(contextHandlerHappen) assert(contextHandlerHappen)
assert(localHandlerHappen) assert(localHandlerHappen)
assert(defaultHandlerHappen)
} }
} }