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 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 ctx.stop(None);
23 }
24}
25
26#[xactor::main]
27async fn main() -> Result<()> {
28 let addr = MyActor.start().await?;
30 addr.wait_for_stop().await;
31 Ok(())
32}