上下文切换
发布 context.become(替换或添加新行为)的两种可能方式是单独提供的,以实现嵌套接收的无杂波符号:
val a = actor(new Act {
become { // this will replace the initial (empty) behavior
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
}
})