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