diff --git a/src/main/kotlin/com/tinder/StateMachine.kt b/src/main/kotlin/com/tinder/StateMachine.kt index c23a9fe..34dc053 100644 --- a/src/main/kotlin/com/tinder/StateMachine.kt +++ b/src/main/kotlin/com/tinder/StateMachine.kt @@ -12,7 +12,7 @@ class StateMachine private construc get() = stateRef.get() fun transition(event: EVENT): Transition { - val transition = synchronized(stateRef) { + val transition = synchronized(this) { val fromState = stateRef.get() val transition = fromState.getTransition(event) if (transition is Transition.Valid) { @@ -20,6 +20,7 @@ class StateMachine private construc } transition } + transition.notifyOnTransition() if (transition is Transition.Valid) { with(transition) { with(fromState) { @@ -30,7 +31,6 @@ class StateMachine private construc } } } - transition.notifyOnTransition() return transition }