mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-18 23:09:23 +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
|
# 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
|
## 0.15.1
|
||||||
|
|
||||||
* `Startup`:
|
* `Startup`:
|
||||||
|
@@ -115,10 +115,21 @@ suspend inline fun <T> runCatchingSafely(
|
|||||||
safely(onException, block)
|
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(
|
suspend inline fun <T> safelyWithResult(
|
||||||
noinline block: suspend CoroutineScope.() -> T
|
noinline block: suspend CoroutineScope.() -> T
|
||||||
): Result<T> = runCatchingSafely(defaultSafelyExceptionHandler, block)
|
): 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
|
* Use this handler in cases you wish to include handling of exceptions by [defaultSafelyWithoutExceptionHandler] and
|
||||||
* returning null at one time
|
* returning null at one time
|
||||||
|
@@ -14,5 +14,5 @@ crypto_js_version=4.1.1
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.15.1
|
version=0.16.1
|
||||||
android_code_version=167
|
android_code_version=169
|
||||||
|
@@ -13,19 +13,19 @@ jb-dokka = "1.7.20"
|
|||||||
klock = "3.4.0"
|
klock = "3.4.0"
|
||||||
uuid = "0.6.0"
|
uuid = "0.6.0"
|
||||||
|
|
||||||
ktor = "2.1.3"
|
ktor = "2.2.1"
|
||||||
|
|
||||||
gh-release = "2.4.1"
|
gh-release = "2.4.1"
|
||||||
|
|
||||||
koin = "3.2.2"
|
koin = "3.2.2"
|
||||||
|
|
||||||
android-gradle = "7.2.2"
|
android-gradle = "7.3.0"
|
||||||
dexcount = "3.1.0"
|
dexcount = "3.1.0"
|
||||||
|
|
||||||
android-coreKtx = "1.9.0"
|
android-coreKtx = "1.9.0"
|
||||||
android-recyclerView = "1.2.1"
|
android-recyclerView = "1.2.1"
|
||||||
android-appCompat = "1.5.1"
|
android-appCompat = "1.5.1"
|
||||||
android-fragment = "1.5.3"
|
android-fragment = "1.5.5"
|
||||||
android-espresso = "3.4.0"
|
android-espresso = "3.4.0"
|
||||||
android-test = "1.1.3"
|
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",
|
||||||
":common:compose",
|
":common:compose",
|
||||||
":matrix",
|
":matrix",
|
||||||
|
":safe_wrapper",
|
||||||
":crypto",
|
":crypto",
|
||||||
":koin",
|
":koin",
|
||||||
":selector:common",
|
":selector:common",
|
||||||
|
@@ -13,11 +13,16 @@ kotlin {
|
|||||||
api internalProject("micro_utils.startup.plugin")
|
api internalProject("micro_utils.startup.plugin")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
jvmTest {
|
||||||
|
dependencies {
|
||||||
|
implementation libs.kt.coroutines.test
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
mainClassName = "dev.inmo.micro_utils.startup.launcher.ServerLauncherKt"
|
mainClassName = "dev.inmo.micro_utils.startup.launcher.MainKt"
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
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.defaultJson
|
||||||
import dev.inmo.micro_utils.startup.launcher.start
|
import dev.inmo.micro_utils.startup.launcher.start
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
import kotlinx.serialization.json.jsonObject
|
import kotlinx.serialization.json.jsonObject
|
||||||
|
import org.koin.core.context.GlobalContext
|
||||||
|
import kotlin.test.BeforeTest
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
|
||||||
class StartupLaunchingTests {
|
class StartupLaunchingTests {
|
||||||
@Test(timeout = 1000L)
|
@BeforeTest
|
||||||
|
fun resetGlobalKoinContext() {
|
||||||
|
kotlin.runCatching { GlobalContext.stopKoin() }
|
||||||
|
}
|
||||||
|
@Test(timeout = 60000L)
|
||||||
fun CheckThatEmptyPluginsListLeadsToEndOfMain() {
|
fun CheckThatEmptyPluginsListLeadsToEndOfMain() {
|
||||||
val emptyJson = defaultJson.encodeToJsonElement(
|
val emptyJson = defaultJson.encodeToJsonElement(
|
||||||
Config.serializer(),
|
Config.serializer(),
|
||||||
Config(emptyList())
|
Config(emptyList())
|
||||||
).jsonObject
|
).jsonObject
|
||||||
|
|
||||||
launchSynchronously {
|
runTest {
|
||||||
val job = launch {
|
val job = launch {
|
||||||
start(emptyJson)
|
start(emptyJson)
|
||||||
}
|
}
|
||||||
job.join()
|
job.join()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Test(timeout = 1000L)
|
@Test(timeout = 60000L)
|
||||||
fun CheckThatHelloWorldPluginsListLeadsToEndOfMain() {
|
fun CheckThatHelloWorldPluginsListLeadsToEndOfMain() {
|
||||||
val emptyJson = defaultJson.encodeToJsonElement(
|
val emptyJson = defaultJson.encodeToJsonElement(
|
||||||
Config.serializer(),
|
Config.serializer(),
|
||||||
Config(listOf(HelloWorldPlugin))
|
Config(listOf(HelloWorldPlugin))
|
||||||
).jsonObject
|
).jsonObject
|
||||||
|
|
||||||
launchSynchronously {
|
runTest {
|
||||||
val job = launch {
|
val job = launch {
|
||||||
start(emptyJson)
|
start(emptyJson)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user