分别提供了两种发出context.become(替换或添加新行为)的可能方式,以使嵌套接收的符号更整洁:
val a = actor(new Act { become { // 这将替代初始(空)行为 case "info" ⇒ sender() ! "A" case "switch" ⇒ becomeStacked { // this will stack upon the "A" behavior case "info" ⇒ sender() ! "B" case "switch" ⇒ unbecome() // return to the "A" behavior } case "lobotomize" ⇒ unbecome() // OH NOES:Actor.emptyBehavior } })