Skip to content

Instantly share code, notes, and snippets.

@adamw
Created May 6, 2015 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamw/fcd9c5db40a3cbaf2d63 to your computer and use it in GitHub Desktop.
Save adamw/fcd9c5db40a3cbaf2d63 to your computer and use it in GitHub Desktop.
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