1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-09-07 17:19:24 +00:00

fix of cancelling absence for subchains which become out of FSM

This commit is contained in:
2025-03-26 09:45:30 +06:00
parent 0afbe8ef2d
commit 8a3a05ef12

View File

@@ -144,11 +144,13 @@ class DefaultBehaviourContextWithFSM<T : State>(
state.context state.context
).apply { ).apply {
stateInitialAction(state) stateInitialAction(state)
}.launchStateHandling( }.run {
launchStateHandling(
state, state,
actualHandlersList actualHandlersList
) )
} }
}
override fun <I : T> add(kClass: KClass<I>, strict: Boolean, handler: BehaviourWithFSMStateHandler<I, T>) { override fun <I : T> add(kClass: KClass<I>, strict: Boolean, handler: BehaviourWithFSMStateHandler<I, T>) {
additionalHandlers.add(BehaviourWithFSMStateHandlerHolder(kClass, strict, handler)) additionalHandlers.add(BehaviourWithFSMStateHandlerHolder(kClass, strict, handler))
@@ -188,7 +190,7 @@ class DefaultBehaviourContextWithFSM<T : State>(
statesJobsMutex.withLock { statesJobsMutex.withLock {
runCatchingSafely { statesJobs.remove(it) ?.cancel() } runCatchingSafely { statesJobs.remove(it) ?.cancel() }
} }
updatesFlows.remove(it.context) updatesFlows.remove(it.context) ?.cancel()
} }
statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(this) { (old, new) -> statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(this) { (old, new) ->
statesJobsMutex.withLock { statesJobsMutex.withLock {
@@ -197,7 +199,7 @@ class DefaultBehaviourContextWithFSM<T : State>(
statesJobs[new] = launch { statePerformer(new) }.apply { enableRemoveOnCompletion(new) } statesJobs[new] = launch { statePerformer(new) }.apply { enableRemoveOnCompletion(new) }
} }
if (old.context != new.context) { if (old.context != new.context) {
updatesFlows.remove(old.context) updatesFlows.remove(old.context) ?.cancel()
} }
} }