Concurrency - . , , concurrency .
JVM , , , .
, , , ask (?). tell (!), . , . , . , .
, - :
case object Inc
case class Count(i)
class IncrementingActor extends Actor {
var i = 0
protected def receive = {
case Inc =>
i += 1
sender ! Count(i)
}
}
class FooActor( counter: ActorRef ) extends Actor {
protected def receive = {
case DoSomething() => {
// Perform some work
counter ! Inc
}
case Count(i) => {
// Do something with the counter result
}
}
}