From 90247667d193f5d94d7f04281872fefb16dbc514 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 19 Jun 2024 19:50:00 +0600 Subject: [PATCH] fix of build --- .../micro_utils/coroutines/LaunchInCurrentThread.kt | 2 +- .../inmo/micro_utils/coroutines/LaunchSynchronously.kt | 10 +++++----- safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt | 4 +++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/coroutines/src/jvmMain/kotlin/dev/inmo/micro_utils/coroutines/LaunchInCurrentThread.kt b/coroutines/src/jvmMain/kotlin/dev/inmo/micro_utils/coroutines/LaunchInCurrentThread.kt index d60e191281e..f3903614434 100644 --- a/coroutines/src/jvmMain/kotlin/dev/inmo/micro_utils/coroutines/LaunchInCurrentThread.kt +++ b/coroutines/src/jvmMain/kotlin/dev/inmo/micro_utils/coroutines/LaunchInCurrentThread.kt @@ -3,7 +3,7 @@ package dev.inmo.micro_utils.coroutines import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -fun launchInCurrentThread(block: suspend CoroutineScope.() -> T): T { +fun launchInCurrentThread(block: suspend () -> T): T { val scope = CoroutineScope(Dispatchers.Unconfined) return scope.launchSynchronously(block) } diff --git a/coroutines/src/jvmMain/kotlin/dev/inmo/micro_utils/coroutines/LaunchSynchronously.kt b/coroutines/src/jvmMain/kotlin/dev/inmo/micro_utils/coroutines/LaunchSynchronously.kt index 7e9bfe5a205..26412f53d38 100644 --- a/coroutines/src/jvmMain/kotlin/dev/inmo/micro_utils/coroutines/LaunchSynchronously.kt +++ b/coroutines/src/jvmMain/kotlin/dev/inmo/micro_utils/coroutines/LaunchSynchronously.kt @@ -2,12 +2,12 @@ package dev.inmo.micro_utils.coroutines import kotlinx.coroutines.* -fun CoroutineScope.launchSynchronously(block: suspend CoroutineScope.() -> T): T { +fun CoroutineScope.launchSynchronously(block: suspend () -> T): T { var result: Result? = null val objectToSynchronize = Object() synchronized(objectToSynchronize) { launch(start = CoroutineStart.UNDISPATCHED) { - result = safelyWithResult(block) + result = runCatchingSafely(block) }.invokeOnCompletion { synchronized(objectToSynchronize) { objectToSynchronize.notifyAll() @@ -20,7 +20,7 @@ fun CoroutineScope.launchSynchronously(block: suspend CoroutineScope.() -> T return result!!.getOrThrow() } -fun launchSynchronously(block: suspend CoroutineScope.() -> T): T = CoroutineScope(Dispatchers.Default).launchSynchronously(block) +fun launchSynchronously(block: suspend () -> T): T = CoroutineScope(Dispatchers.Default).launchSynchronously(block) -fun CoroutineScope.doSynchronously(block: suspend CoroutineScope.() -> T): T = launchSynchronously(block) -fun doSynchronously(block: suspend CoroutineScope.() -> T): T = launchSynchronously(block) +fun CoroutineScope.doSynchronously(block: suspend () -> T): T = launchSynchronously(block) +fun doSynchronously(block: suspend () -> T): T = launchSynchronously(block) diff --git a/safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt b/safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt index 6426ba6703e..2687ac3c3a7 100644 --- a/safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt +++ b/safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt @@ -5,7 +5,9 @@ import dev.inmo.micro_utils.coroutines.runCatchingSafely interface SafeWrapper { fun safe(block: T.() -> R): Result = unsafeTarget().runCatching(block) fun unsafe(block: T.() -> R): R = unsafeTarget().block() - suspend fun safeS(block: suspend T.() -> R): Result = unsafeTarget().runCatchingSafely(block = block) + suspend fun safeS(block: suspend T.() -> R): Result = unsafeTarget().run { + runCatchingSafely(block = { block() }) + } suspend fun unsafeS(block: suspend T.() -> R): R = unsafeTarget().block() fun unsafeTarget(): T