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() } }