scala/ScalaBook/chapter-07/actors3.scala
import scala.actors.Actor._
object actorsExample {
def main(args: Array[String]) {
var done = false
val lousyActor = actor {
loopWhile (! done) {
receive {
case (i : Int, b : Boolean) =>
println("got the Int "+i)
done = b
case (l : Long, b : Boolean) =>
println("got the Long "+l)
done = b
case (f : Float, b : Boolean) =>
println("got the Float "+f)
done = b
case (d : Double, b : Boolean) =>
println("got the Double "+d)
done = b
case (x, b : Boolean) =>
println("don't know what to do with \""+x+"\"")
done = b
}
}
}
lousyActor ! new Tuple2[Any,Boolean](3, false)
lousyActor ! new Tuple2[Any,Boolean](4L, false)
lousyActor ! new Tuple2[Any,Boolean](3.2F, false)
lousyActor ! new Tuple2[Any,Boolean](4.8D, false)
lousyActor ! new Tuple2[Any,Boolean]("help me!", false)
lousyActor ! new Tuple2[Any,Boolean](6, true)
}
}