Function tiny_actor::spawn
source · [−]pub fn spawn<M, E, Fun, Fut>(
config: Config,
fun: Fun
) -> (Child<E, Channel<M>>, Address<M>) where
Fun: FnOnce(Inbox<M>) -> Fut + Send + 'static,
Fut: Future<Output = E> + Send + 'static,
E: Send + 'static,
M: Send + 'static, Expand description
Spawn a new Actor with a single Process. This will return a Child and
and Address. The Process is spawned with a single Inbox.
This will immeadeately start the spawning. await-ing the [Spawn]-future will
wait until the Channel is fully initialized.
Example
let (child, address) =
spawn(Config::default(), |mut inbox: Inbox<u32>| async move {
loop {
let msg = inbox.recv().await;
println!("Received message: {msg:?}");
}
});