Actors case class simple example
I'm almost certainly doing something profoundly stupid which makes this actor not work properly, but I can't see it after a chunk of time staring at it. So I thought I'd ask SO.
I can't get this code to work - in that, if I send it messages such as 4 (which should trigger the default case), nothing is printed, and I can't trip the monitor by sending it a temperature alarm.
What am I doing wrong?
class TemperatureMonitor extends Actor {
var tripped : Boolean = false
var tripTemp : Double = 0.0
def act() {
while (true) {
receive {
开发者_如何学Python case Heartbeat => 0
case TemperatureAlarm(temp) =>
tripped = true
tripTemp = temp
case _ => println("No match")
}
}
}
}
Since you don't show how you create the actor we can only guess. The first thing I would check is that you've started the actor:
val monitor = new TemperatureMonitor
monitor.start
monitor ! 4 // should trigger the default case, as you say
精彩评论