diff --git a/CHANGELOG.md b/CHANGELOG.md index b335f339083..87362ac78ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 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) } } } 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