Merge pull request #211 from InsanusMokrassar/0.16.1

0.16.1
This commit is contained in:
InsanusMokrassar 2022-12-09 19:58:54 +06:00 committed by GitHub
commit 067d9d0d3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 2 deletions

View File

@ -1,5 +1,12 @@
# Changelog
## 0.16.1
* `Coroutines`:
* New `runCatchingSafely`/`safelyWithResult` with receivers
* `SafeWrapper`:
* Module inited
## 0.16.0
* `Versions`:

View File

@ -115,10 +115,21 @@ suspend inline fun <T> runCatchingSafely(
safely(onException, block)
}
suspend inline fun <T, R> T.runCatchingSafely(
noinline onException: ExceptionHandler<R> = defaultSafelyExceptionHandler,
noinline block: suspend T.() -> R
): Result<R> = runCatching {
safely(onException) { block() }
}
suspend inline fun <T> safelyWithResult(
noinline block: suspend CoroutineScope.() -> T
): Result<T> = runCatchingSafely(defaultSafelyExceptionHandler, block)
suspend inline fun <T, R> T.safelyWithResult(
noinline block: suspend T.() -> R
): Result<R> = runCatchingSafely(defaultSafelyExceptionHandler, block)
/**
* Use this handler in cases you wish to include handling of exceptions by [defaultSafelyWithoutExceptionHandler] and
* returning null at one time

View File

@ -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

17
safe_wrapper/build.gradle Normal file
View File

@ -0,0 +1,17 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
id "com.android.library"
}
apply from: "$mppProjectWithSerializationPresetPath"
kotlin {
sourceSets {
commonMain {
dependencies {
api project(":micro_utils.coroutines")
}
}
}
}

View File

@ -0,0 +1,17 @@
package dev.inmo.micro_utils.safe_wrapper
import dev.inmo.micro_utils.coroutines.runCatchingSafely
interface SafeWrapper<T> {
fun <R> safe(block: T.() -> R): Result<R> = unsafeTarget().runCatching(block)
fun <R> unsafe(block: T.() -> R): R = unsafeTarget().block()
suspend fun <R> safeS(block: suspend T.() -> R): Result<R> = unsafeTarget().runCatchingSafely(block = block)
suspend fun <R> unsafeS(block: suspend T.() -> R): R = unsafeTarget().block()
fun unsafeTarget(): T
class Default<T>(private val t: T) : SafeWrapper<T> { override fun unsafeTarget(): T = t }
companion object {
operator fun <T> invoke(t: T) = Default(t)
}
}

View File

@ -0,0 +1 @@
<manifest package="dev.inmo.micro_utils.safe_wrapper"/>

View File

@ -4,6 +4,7 @@ String[] includes = [
":common",
":common:compose",
":matrix",
":safe_wrapper",
":crypto",
":koin",
":selector:common",