From f6d5035c1af2b768bfdf29e14e6c50abb8223607 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 4 Dec 2023 15:44:06 +0600 Subject: [PATCH] small refactor in SpecialMutableStateFlow --- .../coroutines/SpecialMutableStateFlow.kt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/SpecialMutableStateFlow.kt b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/SpecialMutableStateFlow.kt index c1ca2992ba9..ecc421aa5cb 100644 --- a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/SpecialMutableStateFlow.kt +++ b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/SpecialMutableStateFlow.kt @@ -34,12 +34,19 @@ open class SpecialMutableStateFlow( ) protected var _value: T = initialValue - @OptIn(InternalCoroutinesApi::class) override var value: T get() = _value set(value) { doOnChangeAction(value) } + protected val job = internalSharedFlow.subscribe(internalScope) { + doOnChangeAction(it) + } + + override val replayCache: List + get() = publicSharedFlow.replayCache + override val subscriptionCount: StateFlow + get() = publicSharedFlow.subscriptionCount @OptIn(InternalCoroutinesApi::class) override fun compareAndSet(expect: T, update: T): Boolean { @@ -63,14 +70,6 @@ open class SpecialMutableStateFlow( } } } - protected val job = internalSharedFlow.subscribe(internalScope) { - doOnChangeAction(it) - } - - override val replayCache: List - get() = publicSharedFlow.replayCache - override val subscriptionCount: StateFlow - get() = publicSharedFlow.subscriptionCount @ExperimentalCoroutinesApi override fun resetReplayCache() = publicSharedFlow.resetReplayCache()