Skip to content

Commit

Permalink
Reorder callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
zhxnlai committed Jul 11, 2018
1 parent 83a8028 commit 563de6e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/com/tinder/StateMachine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ class StateMachine<STATE : Any, EVENT : Any, SIDE_EFFECT : Any> private construc
get() = stateRef.get()

fun transition(event: EVENT): Transition<STATE, EVENT, SIDE_EFFECT> {
val transition = synchronized(stateRef) {
val transition = synchronized(this) {
val fromState = stateRef.get()
val transition = fromState.getTransition(event)
if (transition is Transition.Valid) {
stateRef.set(transition.toState)
}
transition
}
transition.notifyOnTransition()
if (transition is Transition.Valid) {
with(transition) {
with(fromState) {
Expand All @@ -30,7 +31,6 @@ class StateMachine<STATE : Any, EVENT : Any, SIDE_EFFECT : Any> private construc
}
}
}
transition.notifyOnTransition()
return transition
}

Expand Down

0 comments on commit 563de6e

Please sign in to comment.