wrap initial sending of state to transition listener in CurrentState object with fsm actor ref
This commit is contained in:
parent
c66bbb566d
commit
dfd18968c8
3 changed files with 4 additions and 3 deletions
|
|
@ -10,6 +10,7 @@ import java.util.concurrent.ScheduledFuture
|
|||
|
||||
object FSM {
|
||||
|
||||
case class CurrentState[S](fsmRef: ActorRef, state: S)
|
||||
case class Transition[S](fsmRef: ActorRef, from: S, to: S)
|
||||
case class SubscribeTransitionCallBack(actorRef: ActorRef)
|
||||
case class UnsubscribeTransitionCallBack(actorRef: ActorRef)
|
||||
|
|
@ -319,7 +320,7 @@ trait FSM[S, D] {
|
|||
}
|
||||
case SubscribeTransitionCallBack(actorRef) =>
|
||||
// send current state back as reference point
|
||||
actorRef ! currentState.stateName
|
||||
actorRef ! CurrentState(self, currentState.stateName)
|
||||
transitionCallBackList ::= actorRef
|
||||
case UnsubscribeTransitionCallBack(actorRef) =>
|
||||
transitionCallBackList = transitionCallBackList.filterNot(_ == actorRef)
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ class FSMActorSpec extends JUnitSuite {
|
|||
|
||||
val transitionTester = Actor.actorOf(new Actor { def receive = {
|
||||
case Transition(_, _, _) => transitionCallBackLatch.open
|
||||
case Locked => initialStateLatch.open
|
||||
case CurrentState(_, Locked) => initialStateLatch.open
|
||||
}}).start
|
||||
|
||||
lock ! SubscribeTransitionCallBack(transitionTester)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class FSMTimingSpec
|
|||
|
||||
val fsm = Actor.actorOf(new StateMachine(testActor)).start
|
||||
fsm ! SubscribeTransitionCallBack(testActor)
|
||||
expectMsg(50 millis, Initial)
|
||||
expectMsg(50 millis, CurrentState(fsm, Initial))
|
||||
|
||||
ignoreMsg {
|
||||
case Transition(_, Initial, _) => true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue