Say I define some messages:
sealed trait Command
case class A(i: Int) extends Command
case class B(str: String) extends Command
And then a classic actor as below to handle these messages. On creation I need access to the ActorContext but as a typed context not a classic
class MyActor extends Actor {
val typedContext: ActorContext[Command] = ???
def receive = {
case A(i) =>
// Do something with i
case B(str)
// Do something with str
}
}
I know I can do self.toTyped[Command] to get the typed self reference. But I cannot find anything similar for the ActorContext. How would I go about converting?
There is no conversion from a classic
ActorContextto a typedActorContext. About the only things a typedActorContextcan do that a classicActorContextcan't are:import akka.pattern.ask)import akka.pattern.pipe)For the last one, you can
which will add
spawn/spawnAnonymouswatchunwatchstopmethods which handle typed.