Struct tonari_actor::System
source · pub struct System { /* private fields */ }
Expand description
Systems are responsible for keeping track of their spawned actors, and managing their lifecycles appropriately.
You may run multiple systems in the same application, each system being responsible for its own pool of actors.
Implementations§
source§impl System
impl System
pub fn with_callbacks(name: &str, callbacks: SystemCallbacks) -> Self
sourcepub fn prepare<A>(
&mut self,
actor: A
) -> SpawnBuilderWithoutAddress<'_, A, impl FnOnce() -> A>where
A: Actor + 'static,
pub fn prepare<A>(
&mut self,
actor: A
) -> SpawnBuilderWithoutAddress<'_, A, impl FnOnce() -> A>where
A: Actor + 'static,
Prepare an actor to be spawned. Returns a SpawnBuilderWithoutAddress
which has to be further configured before spawning the actor.
sourcepub fn prepare_fn<A, F>(
&mut self,
factory: F
) -> SpawnBuilderWithoutAddress<'_, A, F>
pub fn prepare_fn<A, F>( &mut self, factory: F ) -> SpawnBuilderWithoutAddress<'_, A, F>
Similar to prepare
, but an actor factory is passed instead
of an Actor
itself. This is used when an actor needs to be
created on its own thread instead of the calling thread.
Returns a SpawnBuilderWithoutAddress
which has to be further
configured before spawning the actor.
sourcepub fn spawn<A>(&mut self, actor: A) -> Result<Addr<A>, ActorError>
pub fn spawn<A>(&mut self, actor: A) -> Result<Addr<A>, ActorError>
Spawn a normal Actor
in the system, returning its address when successful.
This address is created by the system and uses a default capacity.
If you need to customize the address see [prepare
] or [prepare_fn
] above.
sourcepub fn run(&mut self) -> Result<(), ActorError>
pub fn run(&mut self) -> Result<(), ActorError>
Block the current thread until the system is shutdown.
Methods from Deref<Target = SystemHandle>§
sourcepub fn shutdown(&self) -> Result<(), ActorError>
pub fn shutdown(&self) -> Result<(), ActorError>
Stops all actors spawned by this system.
sourcepub fn subscribe_recipient<M: 'static, E: Event + Into<M>>(
&self,
recipient: Recipient<M>
)
pub fn subscribe_recipient<M: 'static, E: Event + Into<M>>( &self, recipient: Recipient<M> )
Subscribe given recipient
to events of type E
. See Context::subscribe()
.