From 023657558ee83e3d2c7000e96f6bb42493badd41 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 9 Dec 2022 10:52:53 +0600 Subject: [PATCH 1/4] start 0.16.1 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fe543a821c..dfc8a3f9c63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.16.1 + ## 0.16.0 * `Versions`: diff --git a/gradle.properties b/gradle.properties index 1eee1b76667..c382506e62f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.16.0 -android_code_version=168 +version=0.16.1 +android_code_version=169 From 43fe06206a3a84201c2a1f1d05b7499ef2e290b9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 9 Dec 2022 11:09:32 +0600 Subject: [PATCH 2/4] add safe wrapper --- safe_wrapper/build.gradle | 7 +++++++ safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt | 13 +++++++++++++ safe_wrapper/src/main/AndroidManifest.xml | 1 + settings.gradle | 1 + 4 files changed, 22 insertions(+) create mode 100644 safe_wrapper/build.gradle create mode 100644 safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt create mode 100644 safe_wrapper/src/main/AndroidManifest.xml diff --git a/safe_wrapper/build.gradle b/safe_wrapper/build.gradle new file mode 100644 index 00000000000..7c54502f100 --- /dev/null +++ b/safe_wrapper/build.gradle @@ -0,0 +1,7 @@ +plugins { + id "org.jetbrains.kotlin.multiplatform" + id "org.jetbrains.kotlin.plugin.serialization" + id "com.android.library" +} + +apply from: "$mppProjectWithSerializationPresetPath" diff --git a/safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt b/safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt new file mode 100644 index 00000000000..f6e911189d5 --- /dev/null +++ b/safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt @@ -0,0 +1,13 @@ +package dev.inmo.micro_utils.safe_wrapper + +interface SafeWrapper { + fun safe (block: T.() -> R): Result = unsafeTarget().runCatching(block) + fun unsafe(block: T.() -> R): R = unsafeTarget().block() + fun unsafeTarget(): T + + class Default(private val t: T) : SafeWrapper { override fun unsafeTarget(): T = t } + + companion object { + operator fun invoke(t: T) = Default(t) + } +} diff --git a/safe_wrapper/src/main/AndroidManifest.xml b/safe_wrapper/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..86e29b98d1c --- /dev/null +++ b/safe_wrapper/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + diff --git a/settings.gradle b/settings.gradle index 069bd208c00..76ab4756747 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,6 +4,7 @@ String[] includes = [ ":common", ":common:compose", ":matrix", + ":safe_wrapper", ":crypto", ":koin", ":selector:common", From ced05a458606e1359e5aaeb096cd6fa2ae3e5473 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 9 Dec 2022 12:14:24 +0600 Subject: [PATCH 3/4] improve default runCatchingSafely/safelyWithResult and add suspend variances of safe/unsafe SafeWrapper interface --- .../dev/inmo/micro_utils/coroutines/HandleSafely.kt | 11 +++++++++++ safe_wrapper/build.gradle | 10 ++++++++++ safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt | 6 +++++- 3 files changed, 26 insertions(+), 1 deletion(-) 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 bc662e79086..c8ab319ea48 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,10 +115,21 @@ suspend inline fun runCatchingSafely( safely(onException, block) } +suspend inline fun T.runCatchingSafely( + noinline onException: ExceptionHandler = defaultSafelyExceptionHandler, + noinline block: suspend T.() -> R +): Result = runCatching { + safely(onException) { block() } +} + suspend inline fun safelyWithResult( noinline block: suspend CoroutineScope.() -> T ): Result = runCatchingSafely(defaultSafelyExceptionHandler, block) +suspend inline fun T.safelyWithResult( + noinline block: suspend T.() -> R +): Result = runCatchingSafely(defaultSafelyExceptionHandler, block) + /** * Use this handler in cases you wish to include handling of exceptions by [defaultSafelyWithoutExceptionHandler] and * returning null at one time diff --git a/safe_wrapper/build.gradle b/safe_wrapper/build.gradle index 7c54502f100..854f51c5dfb 100644 --- a/safe_wrapper/build.gradle +++ b/safe_wrapper/build.gradle @@ -5,3 +5,13 @@ plugins { } apply from: "$mppProjectWithSerializationPresetPath" + +kotlin { + sourceSets { + commonMain { + dependencies { + api project(":micro_utils.coroutines") + } + } + } +} diff --git a/safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt b/safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt index f6e911189d5..6426ba6703e 100644 --- a/safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt +++ b/safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt @@ -1,8 +1,12 @@ package dev.inmo.micro_utils.safe_wrapper +import dev.inmo.micro_utils.coroutines.runCatchingSafely + interface SafeWrapper { - fun safe (block: T.() -> R): Result = unsafeTarget().runCatching(block) + 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 unsafeS(block: suspend T.() -> R): R = unsafeTarget().block() fun unsafeTarget(): T class Default(private val t: T) : SafeWrapper { override fun unsafeTarget(): T = t } From 03f527d83e7483d91b753f29aac56c05bbbb1e68 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 9 Dec 2022 19:46:58 +0600 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfc8a3f9c63..2cb04dda479 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## 0.16.1 +* `Coroutines`: + * New `runCatchingSafely`/`safelyWithResult` with receivers +* `SafeWrapper`: + * Module inited + ## 0.16.0 * `Versions`: