main/
main.rs

1use std::time::Duration;
2use xactor::*;
3
4#[message]
5struct Die;
6
7struct MyActor;
8
9#[async_trait::async_trait]
10impl Actor for MyActor {
11    async fn started(&mut self, ctx: &mut Context<Self>) -> Result<()> {
12        // Send the Die message 3 seconds later
13        ctx.send_later(Die, Duration::from_secs(3));
14        Ok(())
15    }
16}
17
18#[async_trait::async_trait]
19impl Handler<Die> for MyActor {
20    async fn handle(&mut self, ctx: &mut Context<Self>, _msg: Die) {
21        // Stop the actor without error
22        ctx.stop(None);
23    }
24}
25
26#[xactor::main]
27async fn main() -> Result<()> {
28    // Exit the program after 3 seconds
29    let addr = MyActor.start().await?;
30    addr.wait_for_stop().await;
31    Ok(())
32}