Browse files

add FSM.transform, but needs docs (see #1966)

  • Loading branch information...
1 parent 08839b3 commit 6f19e404111cc9fa1382e1b2867ac41a74502d6a @rkuhn rkuhn committed May 7, 2012
View
19 akka-actor-tests/src/test/scala/akka/actor/FSMActorSpec.scala
@@ -262,6 +262,25 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" -> true)) with Im
expectMsg(1 second, IndexedSeq(LogEntry(1, 1, "log"), LogEntry(1, 1, "count"), LogEntry(1, 2, "log")))
}
+ "allow transforming of state results" in {
+ import akka.actor.FSM._
+ val fsmref = system.actorOf(Props(new Actor with FSM[Int, Int] {
+ startWith(0, 0)
+ when(0)(transform {
+ case Event("go", _) stay
+ } {
+ case x goto(1)
+ })
+ when(1) {
+ case _ stay
+ }
+ }))
+ fsmref ! SubscribeTransitionCallBack(testActor)
+ fsmref ! "go"
+ expectMsg(CurrentState(fsmref, 0))
+ expectMsg(Transition(fsmref, 0, 1))
+ }
+
}
}
View
3 akka-actor/src/main/scala/akka/actor/FSM.scala
@@ -253,6 +253,9 @@ trait FSM[S, D] extends Listeners with ActorLogging {
*/
protected final def stop(reason: Reason, stateData: D): State = stay using stateData withStopReason (reason)
+ protected final def transform(func: StateFunction)(andThen: PartialFunction[State, State]): StateFunction =
+ func andThen (andThen orElse { case x x })
+
/**
* Schedule named timer to deliver message after given delay, possibly repeating.
* @param name identifier to be used with cancelTimer()

0 comments on commit 6f19e40

Please sign in to comment.