import scala.actors._ import Actor._ case class SendRequest(rid: String) case class Request(rid: String) case class Response(rid: String) val server = actor { eventloop { case Request(rid) => println("Server got request [%s] from client" format(rid)) sender ! Response(rid) } } } val client = actor { eventloop { case SendRequest(rid) => server ! Request(rid) case Response(rid) => println("Client got response [%s] from server" format(rid)) } } }
Using:
scala> client ! SendRequest("Hello!") Server got request [Hello!] from client Client got response [Hello!] from server
Concerning:
All this message is asynchronous and therefore it uses a reaction.
Actors who use receive are also asynchronous. They simply block the flow, waiting for new messages.
Vasil Remeniuk
source share