Frage

Please take a look at the code below:

  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 _ =>
  }

You can see that I have to completely duplicate the value of case class Begin when I call context.become, that is, passing the whole amount of its parameters. That works, but looks like a code duplication to me. Is there a way to somehow grab the matched value as is and pass it along?

War es hilfreich?

Lösung

Like that:

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 _ =>
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top