From 8a3a05ef12ce597a7fcf3ce5c1e7af02d073ed79 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 26 Mar 2025 09:45:30 +0600 Subject: [PATCH] fix of cancelling absence for subchains which become out of FSM --- .../behaviour_builder/BehaviourContextWithFSM.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt b/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt index 9f802e598a..1d94e4befe 100644 --- a/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt +++ b/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt @@ -144,10 +144,12 @@ class DefaultBehaviourContextWithFSM( state.context ).apply { stateInitialAction(state) - }.launchStateHandling( - state, - actualHandlersList - ) + }.run { + launchStateHandling( + state, + actualHandlersList + ) + } } override fun add(kClass: KClass, strict: Boolean, handler: BehaviourWithFSMStateHandler) { @@ -188,7 +190,7 @@ class DefaultBehaviourContextWithFSM( statesJobsMutex.withLock { runCatchingSafely { statesJobs.remove(it) ?.cancel() } } - updatesFlows.remove(it.context) + updatesFlows.remove(it.context) ?.cancel() } statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(this) { (old, new) -> statesJobsMutex.withLock { @@ -197,7 +199,7 @@ class DefaultBehaviourContextWithFSM( statesJobs[new] = launch { statePerformer(new) }.apply { enableRemoveOnCompletion(new) } } if (old.context != new.context) { - updatesFlows.remove(old.context) + updatesFlows.remove(old.context) ?.cancel() } }