riker-rs / riker

Easily build efficient, highly concurrent and resilient applications. An Actor Framework for Rust.
https://riker.rs
MIT License
1.02k stars 69 forks source link

How to get *another* ActorRef from an ActorSystem #133

Closed igalic closed 4 years ago

igalic commented 4 years ago

i'm trying to store the (reference? to) the ActorSystem in my server's state management facility, to allow the various request handling threads of the server to have access to all the Actors of the ActorSystem in it.

But i don't understand how to get an ActorRef from the ActorSystem again after the Actor has already been started in main(). request handlers are short-lived, and it doesn't make sense for them to start Actors, let alone have all the information passed to them that would allow them to start those Actors.

From what I gather, the only way to do that, is to use Selection

drogus commented 4 years ago

I'm not sure how to do it in Riker, but maybe you could potentially use Arc<Mutex<ActorSystem>> and pass it around like that?

igalic commented 4 years ago

that's basically what I'm already doing (well, without the Mutex yet…)

but then how do i access an actor that's already started?

hardliner66 commented 4 years ago

I think in actor systems it's normal to hold on to references once you create them and pass them to the other actors who need them.

igalic commented 4 years ago

yes, I'd just like to not pass around 5 references, when i'm also holding the ActorSystem

hardliner66 commented 4 years ago

IMO passing around should be preferred, because then all your dependencies are more explicit. But if you don't want to do that, actor selection is probably the way to go.

igalic commented 4 years ago

aye. and that is the route we've taken, so we're on the correct (enough) path