Skip to content

Instantly share code, notes, and snippets.

@momania
Created November 3, 2010 18:28
Show Gist options
  • Save momania/661478 to your computer and use it in GitHub Desktop.
Save momania/661478 to your computer and use it in GitHub Desktop.
Akka FSM Goto 10 FTW!
class GotoFsm extends Actor with FSM[Int, Null] {
notifying {
case Transition(_, 10) => println("Goto 10 ftw!")
}
when(0) {
case _ => goto(10) until 5000
}
when(10) {
case _ => stop
}
startWith(0, null)
onTermination {
case _ => println("Bye bye :-)")
}
}
case object Go
object GotoFsm {
def main(args: Array[String]) {
val gotoFsm = Actor.actorOf[GotoFsm].start
gotoFsm !! Go
}
}
@jboner
Copy link

jboner commented Nov 3, 2010

Cool. Add it to the akka docs.

@retronym
Copy link

retronym commented Nov 3, 2010

() / Unit is a touch more idiomatic Scala than null / Null. Otherwise, I like!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment