scala/ScalaBook/chapter-07/actors4.scala
import scala.actors.Actor
import scala.actors.Actor._
import scala.actors.Futures._
object actorsExample {
def main(args: Array[String]) {
var done = false
val lousyActor = actor {
loopWhile( ! done ) {
react {
case i : Int =>
println("got the Int "+i)
reply(0)
case l : Long =>
println("got the Long "+l)
reply(0)
case f : Float =>
println("got the Float "+f)
reply(0)
case d : Double =>
println("got the Double "+d)
reply(0)
case None =>
println("I must quit!")
done = true
case x =>
println("don't know what to do with \""+x+"\"")
reply(1)
}
}
}
val R : PartialFunction[Any,Unit] = {
case 0 => println("proceeding")
case 1 => lousyActor ! None
}
var x = lousyActor !! (3, R)
x.apply
x = lousyActor !! (4L, R)
x.apply
x= lousyActor !! (3.2F, R)
x.apply
x = lousyActor !! (4.8D, R)
x.apply
x = lousyActor !! ("help me!!", R)
x.apply
lousyActor ! 6
}
}