From c8759843f74168b0b21cd22bd06373a29152d0c8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 23 Jun 2022 17:19:07 +0600 Subject: [PATCH 1/2] start 0.11.6 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b335f339083..dae0eae8ec6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.11.6 + ## 0.11.5 * `Coroutines`: diff --git a/gradle.properties b/gradle.properties index da2cf1f644f..835cff3d3c3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.11.5 -android_code_version=129 +version=0.11.6 +android_code_version=130 From cd22d76fa7ece53c20c4d57629bfb365b44fca89 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 23 Jun 2022 18:47:59 +0600 Subject: [PATCH 2/2] fsms fixes --- CHANGELOG.md | 4 ++++ .../inmo/micro_utils/fsm/common/StatesMachine.kt | 13 +++++-------- .../fsm/common/UpdatableStatesMachine.kt | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dae0eae8ec6..87362ac78ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.11.6 +* `FSM`: + * `Common` + * Several fixes related to the jobs handling + ## 0.11.5 * `Coroutines`: diff --git a/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/StatesMachine.kt b/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/StatesMachine.kt index 81d5f773a96..2c4ffe1c5d7 100644 --- a/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/StatesMachine.kt +++ b/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/StatesMachine.kt @@ -6,6 +6,7 @@ import dev.inmo.micro_utils.coroutines.* import dev.inmo.micro_utils.fsm.common.utils.StateHandlingErrorHandler import dev.inmo.micro_utils.fsm.common.utils.defaultStateHandlingErrorHandler import kotlinx.coroutines.* +import kotlinx.coroutines.flow.asFlow import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock @@ -85,10 +86,10 @@ open class DefaultStatesMachine ( protected open suspend fun performUpdate(state: T) { val newState = launchStateHandling(state, handlers) - if (newState != null) { - statesManager.update(state, newState) - } else { + if (newState == null) { statesManager.endChain(state) + } else { + statesManager.update(state, newState) } } @@ -118,7 +119,7 @@ open class DefaultStatesMachine ( * [StatesManager.endChain]. */ override fun start(scope: CoroutineScope): Job = scope.launchSafelyWithoutExceptions { - statesManager.onStartChain.subscribeSafelyWithoutExceptions(this) { + (statesManager.getActiveStates().asFlow() + statesManager.onStartChain).subscribeSafelyWithoutExceptions(this) { launch { performStateUpdate(Optional.absent(), it, scope.LinkedSupervisorScope()) } } statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(this) { @@ -134,10 +135,6 @@ open class DefaultStatesMachine ( } } } - - statesManager.getActiveStates().forEach { - launch { performStateUpdate(Optional.absent(), it, scope.LinkedSupervisorScope()) } - } } /** diff --git a/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/UpdatableStatesMachine.kt b/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/UpdatableStatesMachine.kt index 3d2542473b2..b2078205623 100644 --- a/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/UpdatableStatesMachine.kt +++ b/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/UpdatableStatesMachine.kt @@ -52,6 +52,7 @@ open class DefaultUpdatableStatesMachine( statesJobs.remove( jobsStates[job] ?: return@withLock ) + jobsStates.remove(job) } } }