Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case object Ping
- case object Pong
- case object Stop
- import scala.actors.Actor
- import scala.actors.Actor._
- class Ping(x: Int, pong: Actor) extends Actor {
- def act() {
- var pingsToGo = x
- pong ! Ping
- println("Ping numer: " + pingsToGo)
- while(true) {
- receive {
- case Pong =>
- if(pingsToGo != 0) {
- pingsToGo-=1
- println("Ping numer: " + pingsToGo)
- pong ! Ping
- } else {
- pong ! Stop
- exit()
- }
- }
- }
- }
- }
- class Pong extends Actor {
- def act() {
- while(true) {
- receive {
- case Ping =>
- print("Pong")
- sender ! Pong
- case Stop =>
- println("Koniec.")
- exit()
- }
- }
- }
- }
- val pong = new Pong
- val ping = new Ping(10, pong)
- pong.start
- ping.start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement