Is <ActorRef>.state.context safe to use? #1759
-
It looks like I can access a nested actor's context easily using 'Parent.state.context.ActorRef.state.context' is there any reason I shouldn't do this? I've seen many discussions in here about how Actors should only communicate via SendParent, however I'd like to avoid storing a whole bunch of state variables in the context of my Parent machine (which spawns many children), but I need to know the state of deeply nested actors from the outside. A direct reference to their context (as above) seems like an extremely convenient way to do it, but I'm wondering if there are potential negative side effects? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's "fine" in v4, but the downside is requiring you to know the implementation details of the ActorRef in order to "reach in" and get the state. In v5, there will likely be a standard API for getting the "state snapshot" of an actor: -Parent.state.context.actorRef.state.context
+Parent.state.context.actorRef.getSnapshot().context That way, it won't matter what "kind" of actor the |
Beta Was this translation helpful? Give feedback.
It's "fine" in v4, but the downside is requiring you to know the implementation details of the ActorRef in order to "reach in" and get the state.
In v5, there will likely be a standard API for getting the "state snapshot" of an actor:
That way, it won't matter what "kind" of actor the
actorRef
is (whether it's spawned from a promise, observable, something else...), you'll be able to get the most recently emitted state from.getSnapshot()
.