alsoInvalidateSync, alsoInvalidateSyncLogging, alsoDoInvalidate -> alsoInvalidateAsync

This commit is contained in:
2025-03-14 15:01:22 +06:00
parent 6fb20fb973
commit 178518db5e
6 changed files with 61 additions and 7 deletions

View File

@@ -6,7 +6,7 @@
* `Exposed`: `0.59.0` -> `0.60.0`
* `Repo`:
* `Cache`:
* Add extensions `alsoInvalidate` and `alsoDoInvalidate`
* Add extensions `alsoInvalidate`, `alsoInvalidateAsync`, `alsoInvalidateSync` and `alsoInvalidateSyncLogging`
* `Koin`:
* Add extensions `singleSuspend` and `factorySuspend` for defining of dependencies with suspendable blocks

View File

@@ -71,7 +71,7 @@ fun <T, M> Flow<T>.subscribeAsync(
it.invoke(markersMap)
}
val job = subscribeSafelyWithoutExceptions(subscope) { data ->
val job = subscribeLoggingDropExceptions(subscope) { data ->
val dataCommand = AsyncSubscriptionCommandData(data, subscope, markerFactory, block) { marker ->
actor.send(
AsyncSubscriptionCommandClearReceiver(marker)

View File

@@ -15,7 +15,7 @@ suspend fun <T : InvalidatableRepo> T.alsoInvalidate() = also {
invalidate()
}
fun <T : InvalidatableRepo> T.alsoDoInvalidate(scope: CoroutineScope) = also {
fun <T : InvalidatableRepo> T.alsoInvalidateAsync(scope: CoroutineScope) = also {
scope.launchLoggingDropExceptions {
invalidate()
}

View File

@@ -0,0 +1,54 @@
package dev.inmo.micro_utils.repos.cache
import dev.inmo.kslog.common.KSLog
import dev.inmo.micro_utils.coroutines.doSynchronously
import dev.inmo.micro_utils.coroutines.runCatchingLogging
import kotlinx.coroutines.CoroutineScope
fun <T : InvalidatableRepo> T.alsoInvalidateSync(
scope: CoroutineScope,
onFailure: suspend (Throwable) -> Unit = {},
) = also {
scope.doSynchronously {
runCatching {
invalidate()
}.onFailure {
onFailure(it)
}
}
}
fun <T : InvalidatableRepo> T.alsoInvalidateSync(
onFailure: suspend (Throwable) -> Unit = {},
) = also {
doSynchronously {
runCatching {
invalidate()
}.onFailure {
onFailure(it)
}
}
}
fun <T : InvalidatableRepo> T.alsoInvalidateSyncLogging(
scope: CoroutineScope,
errorMessageBuilder: CoroutineScope.(Throwable) -> Any = { "Something web wrong" },
logger: KSLog = KSLog,
) = also {
scope.doSynchronously {
runCatchingLogging(errorMessageBuilder, logger) {
invalidate()
}
}
}
fun <T : InvalidatableRepo> T.alsoInvalidateSyncLogging(
errorMessageBuilder: CoroutineScope.(Throwable) -> Any = { "Something web wrong" },
logger: KSLog = KSLog,
) = also {
doSynchronously {
runCatchingLogging(errorMessageBuilder, logger) {
invalidate()
}
}
}

View File

@@ -73,7 +73,7 @@ class KtorCRUDRepoTests : CommonCRUDRepoTests() {
}
val server = io.ktor.server.engine.embeddedServer(
CIO,
34567,
34568,
"127.0.0.1"
) {
install(ContentNegotiation) {
@@ -100,7 +100,7 @@ class KtorCRUDRepoTests : CommonCRUDRepoTests() {
}
}
val crudClient = KtorCRUDRepoClient<ComplexData, Int, SimpleData>(
"http://127.0.0.1:34567",
"http://127.0.0.1:34568",
client,
ContentType.Application.Json
) {

View File

@@ -63,7 +63,7 @@ class KtorKeyValueRepoTests : CommonKeyValueRepoTests() {
val repo = MapKeyValueRepo<Int, ComplexData>(map)
val server = io.ktor.server.engine.embeddedServer(
CIO,
34567,
34569,
"127.0.0.1"
) {
install(ContentNegotiation) {
@@ -91,7 +91,7 @@ class KtorKeyValueRepoTests : CommonKeyValueRepoTests() {
}
}
val crudClient = KtorKeyValueRepoClient<Int, ComplexData>(
"http://127.0.0.1:34567",
"http://127.0.0.1:34569",
client,
ContentType.Application.Json,
Int.serializer(),