use messages::prelude::*;
struct Ping(usize);
struct MyActor {
count: usize,
}
impl Actor for MyActor {}
#[async_trait]
impl Handler<Ping> for MyActor {
type Result = usize;
async fn handle(&mut self, msg: Ping, _: &Context<Self>) -> Self::Result {
self.count += msg.0;
self.count
}
}
fn main() {
smol::block_on(async {
let context = Context::new();
let mut address = context.address();
let actor_handle = smol::spawn(context.run(MyActor { count: 10 }));
let res = address.send(Ping(10)).await;
println!("RESULT: {}", res.unwrap() == 20);
address.stop().await;
address.wait_for_stop().await;
actor_handle.await;
});
}