Created
September 5, 2011 15:52
-
-
Save missingfaktor/1195311 to your computer and use it in GitHub Desktop.
Indira, Nehru, and the Roadside Romeo
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 | |
| case class Letter(sender: Actor, contents: String) | |
| object Indira extends Actor { | |
| private var n = 0 | |
| def act: Unit = loopWhile(n < 10) { | |
| n += 1 | |
| react { | |
| case Letter(Nehru, contents) => { | |
| println("Indira received: " + contents) | |
| Nehru ! Letter(this, "Hello dad!") | |
| } | |
| case Letter(from, _) => { | |
| println("Indira received a letter from an unknown sender. Indira freaked out.") | |
| from ! Letter(this, "Who are you???") | |
| } | |
| } | |
| } | |
| } | |
| object Nehru extends Actor { | |
| private var n = 0 | |
| def act: Unit = { | |
| Indira ! Letter(this, "Hi daughter!") | |
| loopWhile(n < 10) { | |
| n += 1 | |
| react { | |
| case Letter(Indira, contents) => { | |
| println("Nehru received: " + contents) | |
| Indira ! Letter(this, "Hi daughter!") | |
| } | |
| } | |
| } | |
| } | |
| } | |
| case object RoadSideRomeo extends Actor { | |
| def act: Unit = { | |
| Indira ! Letter(this, "Hi sweetie") | |
| } | |
| } | |
| object Main { | |
| def main(args: Array[String]): Unit = { | |
| Indira.start | |
| Nehru.start | |
| RoadSideRomeo.start | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment