Senin, 10 Januari 2011

Actor that transacts messages by specific types

$ cat Main.scala
import scala.actors.Actor._

object Main extends Application {
override def main ( args: Array[String] ) {
val a = actor {
loop {
receive {
case s:String => println ( "I got it! " + s )
case _ => println ( "Sorry..." )
}
}
}

a ! "HELLO!"
a ! 1.5
a ! 9876
a ! "HELLO!"
}
}


$ scalac Main.scala && scala Main
I got it! HELLO!
Sorry...
Sorry...
I got it! HELLO!


$ ls -1
Main$$anonfun$1$$anonfun$apply$2$$anonfun$apply$1.class
Main$$anonfun$1$$anonfun$apply$2.class
Main$$anonfun$1.class
Main$.class
Main.class
Main.scala

Sumber :

http://sites.google.com/site/playingwithscala/home/getting-started/actor/actor-that-processes-messages-by-specific-types

Tidak ada komentar:

Poskan Komentar