Created
May 6, 2015 20:58
-
-
Save adamw/fcd9c5db40a3cbaf2d63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.{Props, ActorSystem, Actor} | |
import akka.pattern.ask | |
import akka.util.Timeout | |
import scala.concurrent.duration._ | |
object Testing extends App { | |
case class Inc(n: Int) | |
class CounterActor extends Actor { | |
private var state = 0 | |
def receive = { | |
case Inc(n) => | |
state += n | |
sender() ! state | |
} | |
} | |
val system = ActorSystem() | |
val counterActor = system.actorOf(Props[CounterActor]) | |
implicit val timeout = Timeout(10.seconds) | |
import system.dispatcher | |
(counterActor ? Inc(20)).mapTo[Int].foreach(println) | |
(counterActor ? Inc(5)).mapTo[Int].foreach(println) | |
Thread.sleep(1000L) | |
system.shutdown() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment