Skip to content

Instantly share code, notes, and snippets.

@rkuhn
Created December 6, 2012 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkuhn/4227672 to your computer and use it in GitHub Desktop.
Save rkuhn/4227672 to your computer and use it in GitHub Desktop.
message-based continuation pattern
import akka.actor.ActorDSL._
case object Work
case object StopIt
implicit val system = akka.actor.ActorSystem()
actor(new Act {
case class ToDo(items: Int, client: ActorRef, v: Double)
become {
case Work => self ! ToDo(100, sender, 0d)
case ToDo(0, client, result) =>
// finished
client ! result
case ToDo(x, client, intermediateValue) =>
// do 1% of the work; pretend that this is costly
val nextValue = (intermediateValue + 0.1) * 2
self ! ToDo(x - 1, client, nextValue)
case StopIt => context stop self
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment