Created
May 1, 2011 20:50
-
-
Save dhinojosa/950863 to your computer and use it in GitHub Desktop.
Thread Koan
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
import actors.Actor._ | |
val guessNumber = actor { | |
loop { | |
react { | |
case (i: Int, caller: Actor) if (i > 64) => caller ! "Too High" | |
case (i: Int, caller: Actor) if (i < 64) => caller ! "Too Low" | |
case (i: Int, caller: Actor) if (i == 64) => { | |
caller ! "Ding" | |
exit('Successful) | |
} | |
} | |
} | |
} | |
val items = List(20, 23, "Boing", 90, 75, 70, 61, 64, "Boom", 65.34) | |
items.foreach { | |
x => | |
guessNumber ! (x, self) | |
self.receiveWithin(100) { | |
case "Too High" => println("Too High") | |
case "Too Low" => println("Too Low") | |
case "Ding" => println("Just Right") | |
case _ => println("Timed Out") | |
} | |
} | |
Thread.sleep(1000) //Wait until all of it is completely done. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment