mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-06 16:49:20 +00:00
add alsoWithUnlockingOnSuccess and alsoWithUnlockingOnSuccessAsync
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
## 0.25.3
|
||||
|
||||
* `Coroutines`:
|
||||
* Add extensions `SmartRWLocker.alsoWithUnlockingOnSuccessAsync` and `SmartRWLocker.alsoWithUnlockingOnSuccess`
|
||||
|
||||
## 0.25.2
|
||||
|
||||
* `Versions`:
|
||||
|
@@ -0,0 +1,23 @@
|
||||
package dev.inmo.micro_utils.coroutines
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
|
||||
suspend inline fun alsoWithUnlockingOnSuccess(
|
||||
vararg lockers: SmartRWLocker,
|
||||
block: suspend () -> Unit
|
||||
): Result<Unit> {
|
||||
return runCatching {
|
||||
block()
|
||||
}.onSuccess {
|
||||
lockers.forEach { it.unlockWrite() }
|
||||
}
|
||||
}
|
||||
|
||||
fun alsoWithUnlockingOnSuccessAsync(
|
||||
scope: CoroutineScope,
|
||||
vararg lockers: SmartRWLocker,
|
||||
block: suspend () -> Unit
|
||||
): Job = scope.launchLoggingDropExceptions {
|
||||
alsoWithUnlockingOnSuccess(*lockers, block = block)
|
||||
}
|
@@ -1,7 +1,9 @@
|
||||
package dev.inmo.micro_utils.repos.cache
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
||||
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
|
||||
interface InvalidatableRepo {
|
||||
/**
|
||||
|
Reference in New Issue
Block a user