pub struct ActorSystem { /* private fields */ }Expand description
A named actor registry with coordinated shutdown.
ActorSystem is a phone book, not a runtime. It does not create or own a
Tokio runtime. Actors spawn on whatever runtime is current via
Handle::try_current().
Implementations§
Source§impl ActorSystem
impl ActorSystem
Sourcepub fn default() -> Arc<ActorSystem>
pub fn default() -> Arc<ActorSystem>
Returns the default system (named "default"), creating it lazily.
This is intentionally not std::default::Default because it returns
Arc<ActorSystem> (shared ownership), not an owned value.
Sourcepub fn create(name: impl Into<String>) -> Result<Arc<ActorSystem>, SpawnError>
pub fn create(name: impl Into<String>) -> Result<Arc<ActorSystem>, SpawnError>
Creates a new named system and registers it in the global systems map.
Returns SpawnError::SystemNameTaken if a system with this name
already exists.
Sourcepub fn create_with(
name: impl Into<String>,
config: SystemConfig,
) -> Result<Arc<ActorSystem>, SpawnError>
pub fn create_with( name: impl Into<String>, config: SystemConfig, ) -> Result<Arc<ActorSystem>, SpawnError>
Creates a new named system with custom configuration.
Returns SpawnError::SystemNameTaken if a system with this name
already exists.
Sourcepub fn get_named(name: &str) -> Option<Arc<ActorSystem>>
pub fn get_named(name: &str) -> Option<Arc<ActorSystem>>
Looks up a named system. Returns None if no system with this name exists.
Sourcepub fn get<A: Actor>(&self, name: &str) -> Option<ActorHandle<A>>
pub fn get<A: Actor>(&self, name: &str) -> Option<ActorHandle<A>>
Looks up a named actor, returning a typed handle.
Returns None if the name is not registered or if the registered actor
is a different type (type mismatch is silent, matching OTP’s
whereis/1 -> undefined semantics).
Sourcepub async fn stop(&self, name: &str) -> Result<(), SendError>
pub async fn stop(&self, name: &str) -> Result<(), SendError>
Stops a named actor gracefully.
Returns SendError::Closed if no actor with the given name is registered.
Sourcepub async fn kill(&self, name: &str) -> Result<(), SendError>
pub async fn kill(&self, name: &str) -> Result<(), SendError>
Force-kills a named actor, bypassing all lifecycle callbacks.
Returns SendError::Closed if no actor with the given name is registered.
Sourcepub fn registered(&self) -> Vec<String>
pub fn registered(&self) -> Vec<String>
Lists all registered actor names in this system.
Sourcepub async fn shutdown(&self)
pub async fn shutdown(&self)
Shuts down all registered actors using the system’s stored policy.
Sourcepub async fn shutdown_with(&self, policy: ShutdownPolicy)
pub async fn shutdown_with(&self, policy: ShutdownPolicy)
Shuts down all registered actors with a custom policy.
All entries are drained from the registry first (releasing locks),
then stop signals are sent. This avoids deadlock with RegistryGuard
drop handlers that also mutate the registry.
Each actor is given up to per_actor_timeout to stop gracefully.
If it does not stop in time, it receives StopReason::Kill.
If the global timeout deadline is exceeded, all remaining actors
are immediately killed.