请查看以下代码:
def receive: Receive = {
case Begin(msg, expectedReply, signalSuccessWith, replyTo, receiver, pause) => {
receiver ! msg
val cancelHandle = context.system.scheduler.schedule(pause, pause, context.self, Retry)
context.become(runtime(Begin(msg, expectedReply, signalSuccessWith, replyTo, receiver, pause), cancelHandle))
}
case _ =>
}
我可以看到,当我调用Begin
时,我必须完全复制案例类context.become
的值,即传递其全部参数。这可行,但看起来像我的代码重复。有没有办法以某种方式按原样获取匹配的值并传递它?
答案 0 :(得分:5)
就像那样:
def receive: Receive = {
case fullMsg @ Begin(msg, expectedReply, signalSuccessWith, replyTo, receiver, pause) => {
receiver ! msg
val cancelHandle = context.system.scheduler.schedule(pause, pause, context.self, Retry)
context.become(runtime(fullMsg, cancelHandle))
}
case _ =>
}