Created
February 26, 2011 02:16
-
-
Save laclefyoshi/844861 to your computer and use it in GitHub Desktop.
2 Actors for Scala
This file contains 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
/** | |
* -*- coding: utf-8 -*- | |
* | |
* Copyright : (c) SAEKI Yoshiyasu | |
* License : MIT-style license | |
* <http://www.opensource.org/licenses/mit-license.php> | |
**/ | |
import scala.actors.Actor | |
class Counter(name:String) extends Actor { | |
def act { | |
receive { | |
case _ => for(i <- 1 to 10) println(name + ": " + i) | |
} | |
} | |
} | |
object ActorTest { | |
def main(args:Array[String]) { | |
// create actor object | |
val c1 = new Counter("c1") | |
val c2 = new Counter("c2") | |
// start actor | |
c1.start | |
c2.start | |
// send message to actor | |
c1 !! "c1" | |
c2 !! "c2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment