我对两个演员(父母 P和孩子 C)有以下顺序操作:
- P看C (
context watch c
) - P不看C (
context unwatch c
) - P优雅地停止C (
c ! PoisonPill
)
我想知道的是;我能保证P 不会收到C的Terminated
事件吗?
这是一段示例代码
class HappensBefore extends App {
class C extends Actor { def receive = {} }
class P extends Actor {
val c = context actorOf Props[C]
context watch c
context unwatch c
c ! PoisonPill
def receive = { case Terminated(child) => println("Oh Noes!") }
}
ActorSystem("test") actorOf Props[P]
}