Skip to content

Commit

Permalink
wrap initial sending of state to transition listener in CurrentState …
Browse files Browse the repository at this point in the history
…object with fsm actor ref
  • Loading branch information
momania committed Jan 3, 2011
1 parent a4ddcd9 commit e5c9e77
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion akka-actor/src/main/scala/akka/actor/FSM.scala
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Expand Up @@ -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)
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit e5c9e77

Please sign in to comment.