pub struct System(/* private fields */);Expand description
A System is a scope within which the actors run.
Implementations§
Source§impl System
impl System
pub fn rc_downgrade(&self) -> SystemWeakRef
Source§impl System
impl System
Sourcepub fn new(config: SystemConfig) -> Self
pub fn new(config: SystemConfig) -> Self
Create a new System using the provided config.
Sourcepub fn config(&self) -> &SystemConfig
pub fn config(&self) -> &SystemConfig
The config with which this System was created.
Source§impl System
impl System
Sourcepub async fn spawn<Behaviour, Args, Message>(
&self,
behaviour: Behaviour,
args: Args,
spawn_opts: SpawnOpts,
) -> Result<ActorID, SysSpawnError>
pub async fn spawn<Behaviour, Args, Message>( &self, behaviour: Behaviour, args: Args, spawn_opts: SpawnOpts, ) -> Result<ActorID, SysSpawnError>
Spawn an actor
Example:
use agner_actors::{System, Context, Event};
async fn actor_behaviour(context: &mut Context<&'static str>, actor_name: &'static str) {
loop {
if let Event::Message(message) = context.next_event().await {
eprintln!("[{}] received: {}", actor_name, message);
}
}
}
let _ = async {
let system = System::new(Default::default());
let alice = system.spawn(actor_behaviour, "Alice", Default::default()).await.expect("Failed to spawn an actor");
let bob = system.spawn(actor_behaviour, "Bob", Default::default()).await.expect("Failed to spawn an actor");
};Sourcepub async fn exit(&self, actor_id: ActorID, exit_reason: Exit)
pub async fn exit(&self, actor_id: ActorID, exit_reason: Exit)
Send SigExit to the specified actor.
Sourcepub fn wait(&self, actor_id: ActorID) -> impl Future<Output = Exit>
pub fn wait(&self, actor_id: ActorID) -> impl Future<Output = Exit>
Wait for the specified actor to terminate, and return upon its termination the
Exit. In case the actor with the specified actor_id does not exist
— return Exit::no_actor() right away.
Sourcepub async fn send<M>(&self, to: ActorID, message: M)where
M: Send + 'static,
pub async fn send<M>(&self, to: ActorID, message: M)where
M: Send + 'static,
Send a single message to the specified actor.
Sourcepub async fn channel<M>(
&self,
to: ActorID,
) -> Result<ActorChannel<M>, SysChannelError>where
M: Send + 'static,
pub async fn channel<M>(
&self,
to: ActorID,
) -> Result<ActorChannel<M>, SysChannelError>where
M: Send + 'static,
Open a channel to the specified actor.
When sending a series of messages to an actor, it may be better from the performance point
of view to open a channel to an actor, rather than sending each message separately using
System::send::<Message>(&self, ActorID, Message).
Sourcepub async fn put_data<D: Any + Send + Sync + 'static>(
&self,
actor_id: ActorID,
data: D,
)
pub async fn put_data<D: Any + Send + Sync + 'static>( &self, actor_id: ActorID, data: D, )
Associate arbitrary data with the specified actor. Upon actor termination that data will be dropped. If no actor with the specified id exists, the data will be dropped right away.