AndreVanDelft / scala

The SubScript extension to the Scala programming language
http://www.subscript-lang.org/
12 stars 1 forks source link

Why not fall back to receive method? #32

Closed AndreVanDelft closed 9 years ago

AndreVanDelft commented 10 years ago

From SubScriptActor:

override def aroundReceive(receive: Actor.Receive, msg: Any) {  
  ...  
  // If a message was handled, Akka will try to match it against a function that can handle any message
  // otherwise it will try to match the message against function that can handle virtually nothing
  // (except LocalObject, which is certainly local and can't be available from the outside)
  case object LocalObject
  super.aroundReceive(if (messageWasHandled) {case _: Any =>} else {case LocalObject =>}, msg)
}

Would it not be handier to support message handling by a regular receive method as fall back option? Then we would not need the LocalObject; the lines would be:

    // If a message had been handled here, Akka should not cause it to be handled again; 
    // yet we must call now super.aroundReceive.
    // We do so with, in place for the receive parameter, 
    // a partial function that can handle any message, and that does nothing.
    // If the message was not handled, then we allow the actor to handle the message in its receive method.
    // This is a fall back option with lightweight message handling 
    // that is supposed not to interfere with the handling in scripts
    super.aroundReceive(if (messageWasHandled) {case _: Any =>} else receive, msg)
anatoliykmetyuk commented 10 years ago

It is a good idea, if you think about it. For example, default receive will still be able to handle nothing, but the user will have an option to override it to decide what to do with certain messages. And we still may have dead letters. Or the user can decide not to override this method at all and work as previously. This increases flexibility, so I think we shall really do things this way.

AndreVanDelft commented 9 years ago

AFAICS it has been implemented some time ago.