Last active
December 19, 2015 10:49
-
-
Save tjweir/5943140 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
| package trial.scalaz | |
| package actors | |
| import java.util.concurrent.CountDownLatch | |
| import scalaz.Scalaz._ | |
| import scalaz.concurrent.Actor | |
| sealed abstract class PingPong | |
| case class Ping(sender: Actor[Pong]) extends PingPong | |
| case class Pong(sender: Actor[Ping]) extends PingPong | |
| object PingPongMain { | |
| def main(args: Array[String]) { | |
| pingActor ! Ping(pongActor) | |
| latch.await() | |
| } | |
| lazy val pingActor: Actor[Ping] = actor { ping => | |
| println("Received Ping, answering with Pong in 500ms.") | |
| Thread.sleep(500) | |
| ping.sender ! Pong(pingActor) | |
| latch.countDown() | |
| } | |
| lazy val pongActor: Actor[Pong] = actor { pong => | |
| println("Received Pong, answering with Ping in 500ms.") | |
| Thread.sleep(500) | |
| pong.sender ! Ping(pongActor) | |
| latch.countDown() | |
| } | |
| lazy val latch = new CountDownLatch(10) | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment