Function tiny_actor::spawn_pooled
source · [−]pub fn spawn_pooled<T, R, I, Fun, Fut>(
iter: impl IntoIterator<Item = I>,
config: Config,
fun: Fun
) -> (ChildPool<R>, Address<T>) where
Fun: FnOnce(I, Inbox<T>) -> Fut + Send + 'static + Clone,
Fut: Future<Output = R> + Send + 'static,
R: Send + 'static,
T: Send + 'static,
I: Send + 'static, Expand description
Spawn a new Actor with a multiple Processes. This will return a ChildPool and
and Address. The Processes are spawned with Inboxes.
The amount of Processes that are spawned is equal to the length of the iterator.
Every process get’s access to a single item within the iterator as it’s first argument.
Example
let (child, address) =
spawn_pooled(0..5, Config::default(), |i, mut inbox: Inbox<u32>| async move {
loop {
let msg = inbox.recv().await;
println!("Received message on actor {i}: {msg:?}");
}
});