KStateMachine / kstatemachine

KStateMachine is a Kotlin DSL library for creating state machines and statecharts.
https://kstatemachine.github.io/kstatemachine/
Boost Software License 1.0
340 stars 19 forks source link

[CRITICAL] onFinished is notified BEFORE final onStateChange #31

Closed kwasny2 closed 2 years ago

kwasny2 commented 2 years ago
    fun StateMachine.stateFlow() = callbackFlow {
        val stateListener = object : StateMachine.Listener {
            override fun onStateChanged(newState: IState) {
                trySendBlocking(newState)
            }
        }
        addListener(stateListener)
        val finishListener = object : IState.Listener {
            override fun onFinished(transitionParams: TransitionParams<*>) {
                channel.close()
            }
        }
        addListener(finishListener)
        awaitClose {
            removeListener(stateListener)
            removeListener(finishListener)
        }
    }

Following code does not pass finalState notification. It is critcal bug, because it is not possible to create any reliable flow of states, rxjava observable, etc..

nsk90 commented 2 years ago

Hi, could you post your state machine structure for testing?

nsk90 commented 2 years ago

fixed in v0.9.5 d4184ec8

kwasny2 commented 2 years ago

Thank you for quick action!