mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-23 00:57:15 +00:00
commit
067d9d0d3b
@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## 0.16.1
|
||||
|
||||
* `Coroutines`:
|
||||
* New `runCatchingSafely`/`safelyWithResult` with receivers
|
||||
* `SafeWrapper`:
|
||||
* Module inited
|
||||
|
||||
## 0.16.0
|
||||
|
||||
* `Versions`:
|
||||
|
@ -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
|
||||
|
@ -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
17
safe_wrapper/build.gradle
Normal 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt
Normal file
17
safe_wrapper/src/commonMain/kotlin/SafeWrapper.kt
Normal 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)
|
||||
}
|
||||
}
|
1
safe_wrapper/src/main/AndroidManifest.xml
Normal file
1
safe_wrapper/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1 @@
|
||||
<manifest package="dev.inmo.micro_utils.safe_wrapper"/>
|
@ -4,6 +4,7 @@ String[] includes = [
|
||||
":common",
|
||||
":common:compose",
|
||||
":matrix",
|
||||
":safe_wrapper",
|
||||
":crypto",
|
||||
":koin",
|
||||
":selector:common",
|
||||
|
Loading…
Reference in New Issue
Block a user