Created
December 6, 2012 19:45
-
-
Save rkuhn/4227672 to your computer and use it in GitHub Desktop.
message-based continuation pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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