From 2215462f991c0ef5cee4f3139da723e39ba68df9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 5 Jun 2021 15:07:27 +0600 Subject: [PATCH 1/5] start 0.5.6 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bde96b2fca..51d2b31054d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.5.6 + ## 0.5.5 * `Versions` diff --git a/gradle.properties b/gradle.properties index fe778f06412..6e33401227b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -45,5 +45,5 @@ dokka_version=1.4.32 # Project data group=dev.inmo -version=0.5.5 -android_code_version=46 +version=0.5.6 +android_code_version=47 From 1f466747f0472c7a308a647fdb1bc67d6321cf2e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 5 Jun 2021 15:08:15 +0600 Subject: [PATCH 2/5] update exposed --- CHANGELOG.md | 3 +++ gradle.properties | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51d2b31054d..7e7f39d5e4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.5.6 +* `Versions` + * `Exposed`: `0.31.1` -> `0.32.1` + ## 0.5.5 * `Versions` diff --git a/gradle.properties b/gradle.properties index 6e33401227b..5d03522015e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ org.gradle.jvmargs=-Xmx2g kotlin_version=1.5.10 kotlin_coroutines_version=1.5.0 kotlin_serialisation_core_version=1.2.1 -kotlin_exposed_version=0.31.1 +kotlin_exposed_version=0.32.1 ktor_version=1.6.0 From 623e0cd369fa8e01a62ff434311c391520d8a4f5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 5 Jun 2021 15:16:07 +0600 Subject: [PATCH 3/5] improve launchSynchronously --- CHANGELOG.md | 3 +++ .../micro_utils/coroutines/HandleSafely.kt | 6 +++++ .../coroutines/LaunchSynchronously.kt | 24 +++++++------------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e7f39d5e4a..08ca25b37c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ * `Versions` * `Exposed`: `0.31.1` -> `0.32.1` +* `Coroutines` + * `JVM` + * `launchSynchronously` and subsequent functions got improved mechanism ## 0.5.5 diff --git a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt index f84e6cdb8e1..4714210efb4 100644 --- a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt +++ b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt @@ -115,6 +115,12 @@ suspend inline fun runCatchingSafely( safely(onException, block) } +suspend inline fun safelyWithResult( + noinline block: suspend CoroutineScope.() -> T +): Result = runCatching { + safely({ throw it }, block) +} + /** * Use this handler in cases you wish to include handling of exceptions by [defaultSafelyWithoutExceptionHandler] and * returning null at one time 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 d5142fcba7f..e4fb735da36 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 @@ -3,27 +3,21 @@ package dev.inmo.micro_utils.coroutines import kotlinx.coroutines.* fun CoroutineScope.launchSynchronously(block: suspend CoroutineScope.() -> T): T { - val deferred = CompletableDeferred() - val objectToSynchronize = java.lang.Object() - val launchCallback = { + var result: Result? = null + val objectToSynchronize = Object() + synchronized(objectToSynchronize) { launch { - safely( - { - deferred.completeExceptionally(it) - } - ) { - deferred.complete(block()) - } + result = safelyWithResult(block) + }.invokeOnCompletion { synchronized(objectToSynchronize) { objectToSynchronize.notifyAll() } } + while (result == null) { + objectToSynchronize.wait() + } } - synchronized(objectToSynchronize) { - launchCallback() - objectToSynchronize.wait() - } - return deferred.getCompleted() + return result!!.getOrThrow() } fun launchSynchronously(block: suspend CoroutineScope.() -> T): T = CoroutineScope(Dispatchers.Default).launchSynchronously(block) From 04ef371337dab806b94531f3b5a829bfc1dbe10f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 5 Jun 2021 15:18:09 +0600 Subject: [PATCH 4/5] update safelyWithResult --- .../kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt index 4714210efb4..8fb0d3ad3f9 100644 --- a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt +++ b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt @@ -117,9 +117,7 @@ suspend inline fun runCatchingSafely( suspend inline fun safelyWithResult( noinline block: suspend CoroutineScope.() -> T -): Result = runCatching { - safely({ throw it }, block) -} +): Result = runCatchingSafely(defaultSafelyExceptionHandler, block) /** * Use this handler in cases you wish to include handling of exceptions by [defaultSafelyWithoutExceptionHandler] and From 2a2da21ff36cf704f17dae8396194925c50c35d0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 5 Jun 2021 15:18:48 +0600 Subject: [PATCH 5/5] fillup safelyWithResult --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08ca25b37c4..9120f045a2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * `Coroutines` * `JVM` * `launchSynchronously` and subsequent functions got improved mechanism + * New method `safelyWithResult` ## 0.5.5