score:0

Your implementation enters only the react as long as you get a Long otherwise it stops. You could wrap it with loop, which is equivalent to while (true), and add a matching expression to stop the actor instead. actor ! 10 will not match case v: Long => ... because an Int is sent to the actor and so the actor will stop.

val actor = new Actor {
  def act() = { 
    loop { 
      react {
        case "stop" => exit()      // you might create a messageobject instead
        case l: Long => addEntry(l)
        case i: Int => addEntry(i.toLong)
      }
    }
  }
}.start()

This would be my suggestion.


Related Query

More Query from same tag