use crate::{
actor::{Actor, LifeCycle},
network::{Network, Socket},
processor::Processing,
};
pub struct Runtime<N: Network> {
network: N,
}
impl<N: Network> Runtime<N> {
#[must_use]
#[allow(clippy::new_without_default)]
pub fn new() -> Self { Self { network: N::new() } }
pub fn spawn<L: LifeCycle>(&mut self, lifecycle: L) -> Actor<L, N> {
let socket = self.network.connect();
Actor::new(lifecycle, socket)
}
pub fn process<L: LifeCycle>(&self, actor: Actor<L, N>) -> Processing<Actor<L, N>, L, N> {
for &type_id in actor.handlers.keys() {
self.network.subscribe(actor.socket.address(), type_id);
}
actor.into_processing()
}
#[must_use]
pub const fn network(&self) -> &N { &self.network }
}