Is it safe to close the actor context in akka scheduler

I know that it is unsafe to close the call to the sender method or the internal state of the actor in the Future or the scheduler, but what about the context of the actor? What is in ActorContext ? Is it safe to close the actor context in the scheduler or future callback, for example?

 def receive: Receive = { case Msg => system.scheduler.scheduleOnce(1 second) { context.actorOf[ChildActor] } } 
+6
source share
1 answer

No, it’s not safe to close the actor’s context. From akka source:

 /** * Stores the context for this actor, including self, and sender. * It is implicit to support operations such as `forward`. * * WARNING: Only valid within the Actor itself, so do not close over it and * publish it to other threads! * * [[akka.actor.ActorContext]] is the Scala API. `getContext` returns a * [[akka.actor.UntypedActorContext]], which is the Java API of the actor * context. */ implicit val context: ActorContext = { ... 
+6
source

Source: https://habr.com/ru/post/979281/


All Articles