Skip to content

Instantly share code, notes, and snippets.

@laclefyoshi
Created February 26, 2011 02:16
Show Gist options
  • Save laclefyoshi/844861 to your computer and use it in GitHub Desktop.
Save laclefyoshi/844861 to your computer and use it in GitHub Desktop.
2 Actors for Scala
/**
* -*- 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