Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 6f19e404111cc9fa1382e1b2867ac41a74502d6a 1 parent 08839b3
Roland Kuhn rkuhn authored
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
262 262 expectMsg(1 second, IndexedSeq(LogEntry(1, 1, "log"), LogEntry(1, 1, "count"), LogEntry(1, 2, "log")))
263 263 }
264 264
  265 + "allow transforming of state results" in {
  266 + import akka.actor.FSM._
  267 + val fsmref = system.actorOf(Props(new Actor with FSM[Int, Int] {
  268 + startWith(0, 0)
  269 + when(0)(transform {
  270 + case Event("go", _) ⇒ stay
  271 + } {
  272 + case x ⇒ goto(1)
  273 + })
  274 + when(1) {
  275 + case _ ⇒ stay
  276 + }
  277 + }))
  278 + fsmref ! SubscribeTransitionCallBack(testActor)
  279 + fsmref ! "go"
  280 + expectMsg(CurrentState(fsmref, 0))
  281 + expectMsg(Transition(fsmref, 0, 1))
  282 + }
  283 +
265 284 }
266 285
267 286 }
3  akka-actor/src/main/scala/akka/actor/FSM.scala
@@ -253,6 +253,9 @@ trait FSM[S, D] extends Listeners with ActorLogging {
253 253 */
254 254 protected final def stop(reason: Reason, stateData: D): State = stay using stateData withStopReason (reason)
255 255
  256 + protected final def transform(func: StateFunction)(andThen: PartialFunction[State, State]): StateFunction =
  257 + func andThen (andThen orElse { case x ⇒ x })
  258 +
256 259 /**
257 260 * Schedule named timer to deliver message after given delay, possibly repeating.
258 261 * @param name identifier to be used with cancelTimer()

0 comments on commit 6f19e40

Please sign in to comment.
Something went wrong with that request. Please try again.