use std::time::Duration;
use tokio::time::sleep;
use zestors::{messaging::RecvError, prelude::*};
async fn inbox_actor(mut inbox: Inbox<()>) {
loop {
if let Err(RecvError::Halted) = inbox.recv().await {
break ();
}
}
}
async fn halter_actor(halter: Halter) {
halter.await
}
#[tokio::main]
async fn main() {
let _ = spawn_with(Link::default(), (), halter_actor);
let _ = spawn_with(Link::default(), Capacity::default(), inbox_actor);
let (child, address) = spawn(inbox_actor);
drop(child);
sleep(Duration::from_millis(10)).await;
assert!(address.has_exited());
let (child, address) = spawn_with(Link::Detached, Capacity::default(), inbox_actor);
drop(child);
sleep(Duration::from_millis(10)).await;
assert!(!address.has_exited());
let (mut child_pool, _address) = spawn_many(0..10, |i, inbox| async move {
println!("Spawning process nr {i}");
inbox_actor(inbox).await
});
child_pool
.spawn_onto(|_inbox: Inbox<()>| async move { () })
.unwrap();
let mut child_pool = child_pool.into_dyn();
child_pool
.try_spawn_onto(|_inbox: Inbox<()>| async move { () })
.unwrap();
child_pool
.try_spawn_onto(|_inbox: MultiHalter| async move { unreachable!() })
.unwrap_err();
}