mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-17 14:29:24 +00:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
03f527d83e | |||
ced05a4586 | |||
43fe06206a | |||
023657558e | |||
9b0b726c80 | |||
4ee67321c4 | |||
59f1f2e59b | |||
0766d48b7c | |||
e18903b9e9 | |||
d0eecdead2 | |||
cc4a83a033 | |||
1cf911bbde | |||
36d73d5023 | |||
c395242e3e | |||
cd9cd7cc5d |
13
CHANGELOG.md
13
CHANGELOG.md
@@ -1,5 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
## 0.16.1
|
||||
|
||||
* `Coroutines`:
|
||||
* New `runCatchingSafely`/`safelyWithResult` with receivers
|
||||
* `SafeWrapper`:
|
||||
* Module inited
|
||||
|
||||
## 0.16.0
|
||||
|
||||
* `Versions`:
|
||||
* `Ktor`: `2.1.3` -> `2.2.1`
|
||||
* `Android Fragment`: `1.5.3` -> `1.5.5`
|
||||
|
||||
## 0.15.1
|
||||
|
||||
* `Startup`:
|
||||
|
@@ -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.15.1
|
||||
android_code_version=167
|
||||
version=0.16.1
|
||||
android_code_version=169
|
||||
|
@@ -13,19 +13,19 @@ jb-dokka = "1.7.20"
|
||||
klock = "3.4.0"
|
||||
uuid = "0.6.0"
|
||||
|
||||
ktor = "2.1.3"
|
||||
ktor = "2.2.1"
|
||||
|
||||
gh-release = "2.4.1"
|
||||
|
||||
koin = "3.2.2"
|
||||
|
||||
android-gradle = "7.2.2"
|
||||
android-gradle = "7.3.0"
|
||||
dexcount = "3.1.0"
|
||||
|
||||
android-coreKtx = "1.9.0"
|
||||
android-recyclerView = "1.2.1"
|
||||
android-appCompat = "1.5.1"
|
||||
android-fragment = "1.5.3"
|
||||
android-fragment = "1.5.5"
|
||||
android-espresso = "3.4.0"
|
||||
android-test = "1.1.3"
|
||||
|
||||
|
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",
|
||||
|
@@ -13,11 +13,16 @@ kotlin {
|
||||
api internalProject("micro_utils.startup.plugin")
|
||||
}
|
||||
}
|
||||
jvmTest {
|
||||
dependencies {
|
||||
implementation libs.kt.coroutines.test
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "dev.inmo.micro_utils.startup.launcher.ServerLauncherKt"
|
||||
mainClassName = "dev.inmo.micro_utils.startup.launcher.MainKt"
|
||||
}
|
||||
|
||||
java {
|
||||
|
@@ -4,32 +4,39 @@ import dev.inmo.micro_utils.startup.launcher.HelloWorldPlugin
|
||||
import dev.inmo.micro_utils.startup.launcher.defaultJson
|
||||
import dev.inmo.micro_utils.startup.launcher.start
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import org.koin.core.context.GlobalContext
|
||||
import kotlin.test.BeforeTest
|
||||
import kotlin.test.Test
|
||||
|
||||
class StartupLaunchingTests {
|
||||
@Test(timeout = 1000L)
|
||||
@BeforeTest
|
||||
fun resetGlobalKoinContext() {
|
||||
kotlin.runCatching { GlobalContext.stopKoin() }
|
||||
}
|
||||
@Test(timeout = 60000L)
|
||||
fun CheckThatEmptyPluginsListLeadsToEndOfMain() {
|
||||
val emptyJson = defaultJson.encodeToJsonElement(
|
||||
Config.serializer(),
|
||||
Config(emptyList())
|
||||
).jsonObject
|
||||
|
||||
launchSynchronously {
|
||||
runTest {
|
||||
val job = launch {
|
||||
start(emptyJson)
|
||||
}
|
||||
job.join()
|
||||
}
|
||||
}
|
||||
@Test(timeout = 1000L)
|
||||
@Test(timeout = 60000L)
|
||||
fun CheckThatHelloWorldPluginsListLeadsToEndOfMain() {
|
||||
val emptyJson = defaultJson.encodeToJsonElement(
|
||||
Config.serializer(),
|
||||
Config(listOf(HelloWorldPlugin))
|
||||
).jsonObject
|
||||
|
||||
launchSynchronously {
|
||||
runTest {
|
||||
val job = launch {
|
||||
start(emptyJson)
|
||||
}
|
||||
|
Reference in New Issue
Block a user