mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-07 09:09:26 +00:00
alsoInvalidateSync, alsoInvalidateSyncLogging, alsoDoInvalidate -> alsoInvalidateAsync
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
* `Exposed`: `0.59.0` -> `0.60.0`
|
* `Exposed`: `0.59.0` -> `0.60.0`
|
||||||
* `Repo`:
|
* `Repo`:
|
||||||
* `Cache`:
|
* `Cache`:
|
||||||
* Add extensions `alsoInvalidate` and `alsoDoInvalidate`
|
* Add extensions `alsoInvalidate`, `alsoInvalidateAsync`, `alsoInvalidateSync` and `alsoInvalidateSyncLogging`
|
||||||
* `Koin`:
|
* `Koin`:
|
||||||
* Add extensions `singleSuspend` and `factorySuspend` for defining of dependencies with suspendable blocks
|
* Add extensions `singleSuspend` and `factorySuspend` for defining of dependencies with suspendable blocks
|
||||||
|
|
||||||
|
@@ -71,7 +71,7 @@ fun <T, M> Flow<T>.subscribeAsync(
|
|||||||
it.invoke(markersMap)
|
it.invoke(markersMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
val job = subscribeSafelyWithoutExceptions(subscope) { data ->
|
val job = subscribeLoggingDropExceptions(subscope) { data ->
|
||||||
val dataCommand = AsyncSubscriptionCommandData(data, subscope, markerFactory, block) { marker ->
|
val dataCommand = AsyncSubscriptionCommandData(data, subscope, markerFactory, block) { marker ->
|
||||||
actor.send(
|
actor.send(
|
||||||
AsyncSubscriptionCommandClearReceiver(marker)
|
AsyncSubscriptionCommandClearReceiver(marker)
|
||||||
|
@@ -15,7 +15,7 @@ suspend fun <T : InvalidatableRepo> T.alsoInvalidate() = also {
|
|||||||
invalidate()
|
invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T : InvalidatableRepo> T.alsoDoInvalidate(scope: CoroutineScope) = also {
|
fun <T : InvalidatableRepo> T.alsoInvalidateAsync(scope: CoroutineScope) = also {
|
||||||
scope.launchLoggingDropExceptions {
|
scope.launchLoggingDropExceptions {
|
||||||
invalidate()
|
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(
|
val server = io.ktor.server.engine.embeddedServer(
|
||||||
CIO,
|
CIO,
|
||||||
34567,
|
34568,
|
||||||
"127.0.0.1"
|
"127.0.0.1"
|
||||||
) {
|
) {
|
||||||
install(ContentNegotiation) {
|
install(ContentNegotiation) {
|
||||||
@@ -100,7 +100,7 @@ class KtorCRUDRepoTests : CommonCRUDRepoTests() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val crudClient = KtorCRUDRepoClient<ComplexData, Int, SimpleData>(
|
val crudClient = KtorCRUDRepoClient<ComplexData, Int, SimpleData>(
|
||||||
"http://127.0.0.1:34567",
|
"http://127.0.0.1:34568",
|
||||||
client,
|
client,
|
||||||
ContentType.Application.Json
|
ContentType.Application.Json
|
||||||
) {
|
) {
|
||||||
|
@@ -63,7 +63,7 @@ class KtorKeyValueRepoTests : CommonKeyValueRepoTests() {
|
|||||||
val repo = MapKeyValueRepo<Int, ComplexData>(map)
|
val repo = MapKeyValueRepo<Int, ComplexData>(map)
|
||||||
val server = io.ktor.server.engine.embeddedServer(
|
val server = io.ktor.server.engine.embeddedServer(
|
||||||
CIO,
|
CIO,
|
||||||
34567,
|
34569,
|
||||||
"127.0.0.1"
|
"127.0.0.1"
|
||||||
) {
|
) {
|
||||||
install(ContentNegotiation) {
|
install(ContentNegotiation) {
|
||||||
@@ -91,7 +91,7 @@ class KtorKeyValueRepoTests : CommonKeyValueRepoTests() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val crudClient = KtorKeyValueRepoClient<Int, ComplexData>(
|
val crudClient = KtorKeyValueRepoClient<Int, ComplexData>(
|
||||||
"http://127.0.0.1:34567",
|
"http://127.0.0.1:34569",
|
||||||
client,
|
client,
|
||||||
ContentType.Application.Json,
|
ContentType.Application.Json,
|
||||||
Int.serializer(),
|
Int.serializer(),
|
||||||
|
Reference in New Issue
Block a user