From 6390f882722a8805eeb53a17c7a8ad139664804d Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sat, 12 Aug 2023 18:55:45 +0200 Subject: [PATCH] Correctly emit changed values "SharedFlow::emit" blocked the flow due not being called in a new coroutine. --- .../src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt index fd56b6a0f1..fe94b6f59f 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt @@ -20,6 +20,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.onEach import xyz.nulldev.ts.config.GlobalConfigManager import xyz.nulldev.ts.config.SystemPropertyOverridableConfigModule @@ -108,7 +109,7 @@ class ServerConfig(getConfig: () -> Config, val moduleName: String = SERVER_CONF } val sharedFlow = MutableSharedFlow(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST) - actualFlow.distinctUntilChanged().onEach { sharedFlow.emit(it) }.launchIn(mutableConfigValueScope) + actualFlow.distinctUntilChanged().mapLatest { sharedFlow.emit(it) }.launchIn(mutableConfigValueScope) sharedFlow.onEach { onChange(it) }.launchIn(mutableConfigValueScope) }