mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-11-15 11:30:25 +00:00
alsoInvalidateSync, alsoInvalidateSyncLogging, alsoDoInvalidate -> alsoInvalidateAsync
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
54
repos/cache/src/jvmMain/kotlin/InvalidateSynchronously.kt
vendored
Normal file
54
repos/cache/src/jvmMain/kotlin/InvalidateSynchronously.kt
vendored
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
) {
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user