我有一个带有接收方法的演员:
def receive: Actor.Receive = {
case Tick =>
val child = context.system.actorOf(...) // create actor
context.watch(child)
child ! something
case AskRunningJobs =>
log.info(s"My children: ${context.children.toList.length}")
log.info(s"My children: ${context.children.toList.map(_.path.toSerializationFormat).mkString(" ||| ")}")
sender ! RunningJobs(context.children.toList.length)
case unknown =>
log.warning(s"unknown message: $unknown")
}
我有详细的日志输出,我可以清楚地看到孩子们已经创建并且正在运行。但
context.children.toList.length
始终为零。为什么?我正在使用 TestKit 运行我的演员。