mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2026-04-19 07:52:29 +00:00
Compare commits
10 Commits
04f82a03bf
...
0.25.4
| Author | SHA1 | Date | |
|---|---|---|---|
| b1a96b6ecb | |||
| 66dac2086c | |||
| e269d0d206 | |||
| 5d95c3eb9c | |||
| 26650e9b6c | |||
| 7339dd8354 | |||
| 8ae983971a | |||
| d46cc3b09c | |||
| dfd23f8d60 | |||
| 28eb1a11e6 |
10
CHANGELOG.md
10
CHANGELOG.md
@@ -1,5 +1,15 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.25.4
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Ktor`: `3.1.1` -> `3.1.2`
|
||||||
|
* `Koin`: `4.0.2` -> `4.0.4`
|
||||||
|
* `Coroutines`:
|
||||||
|
* Add `SmartKeyRWLocker.withWriteLocks` extension with vararg keys
|
||||||
|
* `Transactions`:
|
||||||
|
* Fix order of rollback actions calling
|
||||||
|
|
||||||
## 0.25.3
|
## 0.25.3
|
||||||
|
|
||||||
* `Coroutines`:
|
* `Coroutines`:
|
||||||
|
|||||||
@@ -222,3 +222,5 @@ suspend inline fun <T, R> SmartKeyRWLocker<T>.withWriteLocks(keys: Iterable<T>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend inline fun <T, R> SmartKeyRWLocker<T>.withWriteLocks(vararg keys: T, action: () -> R): R = withWriteLocks(keys.asIterable(), action)
|
||||||
|
|||||||
@@ -64,6 +64,56 @@ class SmartKeyRWLockerTests {
|
|||||||
assertFalse { locker.isWriteLocked(testKey) }
|
assertFalse { locker.isWriteLocked(testKey) }
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
|
fun readLockFailedOnWriteLockKeyTest() = runTest {
|
||||||
|
val locker = SmartKeyRWLocker<String>()
|
||||||
|
val testKey = "test"
|
||||||
|
locker.lockWrite(testKey)
|
||||||
|
|
||||||
|
assertTrue { locker.isWriteLocked(testKey) }
|
||||||
|
|
||||||
|
assertFails {
|
||||||
|
realWithTimeout(1.seconds) {
|
||||||
|
locker.acquireRead()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(locker.readSemaphore().maxPermits - 1, locker.readSemaphore().freePermits)
|
||||||
|
|
||||||
|
locker.unlockWrite(testKey)
|
||||||
|
assertFalse { locker.isWriteLocked(testKey) }
|
||||||
|
|
||||||
|
realWithTimeout(1.seconds) {
|
||||||
|
locker.acquireRead()
|
||||||
|
}
|
||||||
|
assertEquals(locker.readSemaphore().maxPermits - 1, locker.readSemaphore().freePermits)
|
||||||
|
assertTrue { locker.releaseRead() }
|
||||||
|
assertEquals(locker.readSemaphore().maxPermits, locker.readSemaphore().freePermits)
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
fun writeLockFailedOnWriteLockKeyTest() = runTest {
|
||||||
|
val locker = SmartKeyRWLocker<String>()
|
||||||
|
val testKey = "test"
|
||||||
|
locker.lockWrite(testKey)
|
||||||
|
|
||||||
|
assertTrue { locker.isWriteLocked(testKey) }
|
||||||
|
|
||||||
|
assertFails {
|
||||||
|
realWithTimeout(1.seconds) {
|
||||||
|
locker.lockWrite()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertFalse(locker.isWriteLocked())
|
||||||
|
|
||||||
|
locker.unlockWrite(testKey)
|
||||||
|
assertFalse { locker.isWriteLocked(testKey) }
|
||||||
|
|
||||||
|
realWithTimeout(1.seconds) {
|
||||||
|
locker.lockWrite()
|
||||||
|
}
|
||||||
|
assertTrue(locker.isWriteLocked())
|
||||||
|
assertTrue { locker.unlockWrite() }
|
||||||
|
assertFalse(locker.isWriteLocked())
|
||||||
|
}
|
||||||
|
@Test
|
||||||
fun readsBlockingGlobalWrite() = runTest {
|
fun readsBlockingGlobalWrite() = runTest {
|
||||||
val locker = SmartKeyRWLocker<String>()
|
val locker = SmartKeyRWLocker<String>()
|
||||||
|
|
||||||
|
|||||||
@@ -15,5 +15,5 @@ crypto_js_version=4.1.1
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.25.3
|
version=0.25.4
|
||||||
android_code_version=293
|
android_code_version=294
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[versions]
|
[versions]
|
||||||
|
|
||||||
kt = "2.1.10"
|
kt = "2.1.20"
|
||||||
kt-serialization = "1.8.0"
|
kt-serialization = "1.8.0"
|
||||||
kt-coroutines = "1.10.1"
|
kt-coroutines = "1.10.1"
|
||||||
|
|
||||||
@@ -15,15 +15,15 @@ sqlite = "3.49.1.0"
|
|||||||
korlibs = "5.4.0"
|
korlibs = "5.4.0"
|
||||||
uuid = "0.8.4"
|
uuid = "0.8.4"
|
||||||
|
|
||||||
ktor = "3.1.1"
|
ktor = "3.1.2"
|
||||||
|
|
||||||
gh-release = "2.5.2"
|
gh-release = "2.5.2"
|
||||||
|
|
||||||
koin = "4.0.2"
|
koin = "4.0.4"
|
||||||
|
|
||||||
okio = "3.10.2"
|
okio = "3.10.2"
|
||||||
|
|
||||||
ksp = "2.1.10-1.0.31"
|
ksp = "2.1.20-1.0.31"
|
||||||
kotlin-poet = "1.18.1"
|
kotlin-poet = "1.18.1"
|
||||||
|
|
||||||
versions = "0.51.0"
|
versions = "0.51.0"
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id "org.jetbrains.kotlin.multiplatform"
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
id "org.jetbrains.kotlin.plugin.serialization"
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
id "application"
|
|
||||||
id "com.google.devtools.ksp"
|
id "com.google.devtools.ksp"
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$mppJvmJsLinuxMingwProject"
|
apply from: "$mppJvmJsLinuxMingwProject"
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
|
jvm {
|
||||||
|
binaries {
|
||||||
|
executable {
|
||||||
|
mainClass.set("dev.inmo.micro_utils.startup.launcher.MainKt")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -23,10 +29,6 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
|
||||||
mainClassName = "dev.inmo.micro_utils.startup.launcher.MainKt"
|
|
||||||
}
|
|
||||||
|
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package dev.inmo.micro_utils.transactions
|
|||||||
|
|
||||||
typealias TransactionDSLRollbackLambda = suspend (Throwable) -> Unit
|
typealias TransactionDSLRollbackLambda = suspend (Throwable) -> Unit
|
||||||
class TransactionsDSL internal constructor() {
|
class TransactionsDSL internal constructor() {
|
||||||
internal val rollbackActions = LinkedHashSet<TransactionDSLRollbackLambda>()
|
internal val rollbackActions = ArrayList<TransactionDSLRollbackLambda>()
|
||||||
|
|
||||||
internal fun addRollbackAction(rollbackAction: TransactionDSLRollbackLambda) {
|
internal fun addRollbackAction(rollbackAction: TransactionDSLRollbackLambda) {
|
||||||
rollbackActions.add(rollbackAction)
|
rollbackActions.add(rollbackAction)
|
||||||
@@ -71,9 +71,10 @@ suspend fun <T> doSuspendTransaction(
|
|||||||
return runCatching {
|
return runCatching {
|
||||||
transactionsDSL.block()
|
transactionsDSL.block()
|
||||||
}.onFailure { e ->
|
}.onFailure { e ->
|
||||||
transactionsDSL.rollbackActions.forEach {
|
for (i in transactionsDSL.rollbackActions.lastIndex downTo 0) {
|
||||||
|
val rollbackAction = transactionsDSL.rollbackActions[i]
|
||||||
runCatching {
|
runCatching {
|
||||||
it.invoke(e)
|
rollbackAction.invoke(e)
|
||||||
}.onFailure { ee ->
|
}.onFailure { ee ->
|
||||||
onRollbackStepError(ee)
|
onRollbackStepError(ee)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user