#[abcgen::actor_module] #[allow(unused)] mod actor { use abcgen::{actor, message_handler, send_task, AbcgenError, PinnedFuture, Task}; #[actor] pub struct MyActor { pub some_value: i32, } impl MyActor { pub async fn start(&mut self, task_sender: TaskSender) { println!("Starting"); // here you can spawn some tasks using tokio::spawn // or enqueue some tasks into the actor's main loop by sending them to task_sender tokio::spawn(async move { tokio::time::sleep(std::time::Duration::from_secs(1)).await; send_task!( task_sender(this) => { this.example_task().await; } ); }); } pub async fn shutdown(&mut self) { println!("Shutting down"); } #[message_handler] async fn get_value(&mut self, name: &'static str) -> Result { match name { "some_value" => Ok(self.some_value), _ => Err("Invalid name"), } } async fn example_task(&mut self) { println!("Example task executed"); } } } #[tokio::main] async fn main() { let actor: actor::MyActorProxy = actor::MyActor { some_value: 32 }.run(); let the_value = actor.get_value("some_value").await.unwrap(); assert!(matches!(the_value, Ok(32))); let the_value = actor.get_value("some_other_value").await.unwrap(); assert!(matches!(the_value, Err("Invalid name"))); }