use crate::actor::Actor;
use crate::actor_ref::ActorRef;
use crate::spawn::{spawn_actor, DEFAULT_BUFFER_SIZE};
#[derive(Debug, Clone)] pub struct ActorSystem {
name: String,
}
impl ActorSystem {
pub fn new(name: &str) -> Self {
println!("Initializing ActorSystem '{}'...", name);
ActorSystem {
name: name.to_string(),
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn spawn<A: Actor>(&self, actor: A, buffer: usize) -> ActorRef<A>
where
A::State: PartialEq,
{
println!(
"ActorSystem '{}' spawning actor with buffer size {}...",
self.name, buffer
);
spawn_actor(actor, buffer)
}
pub fn spawn_default<A: Actor>(&self, actor: A) -> ActorRef<A>
where
A::State: PartialEq,
{
println!(
"ActorSystem '{}' spawning actor with default buffer size...",
self.name
);
self.spawn(actor, DEFAULT_BUFFER_SIZE)
}
}