use std::error::Error;
use std::time::Duration;
use tyra::prelude::*;
struct TestMessage {}
impl TestMessage {
pub fn new() -> Self {
Self {}
}
}
impl ActorMessage for TestMessage {}
struct TestActor {}
impl TestActor {
pub fn new() -> Self {
Self {}
}
}
impl Actor for TestActor {}
struct TestActorFactory {}
impl TestActorFactory {
pub fn new() -> Self {
Self {}
}
}
impl ActorFactory<TestActor> for TestActorFactory {
fn new_actor(
&mut self,
_context: ActorContext<TestActor>,
) -> Result<TestActor, Box<dyn Error>> {
Ok(TestActor::new())
}
}
impl Handler<TestMessage> for TestActor {
fn handle(
&mut self,
_msg: TestMessage,
context: &ActorContext<Self>,
) -> Result<ActorResult, Box<dyn Error>> {
println!("HELLO WORLD!");
context.system.stop(Duration::from_millis(1000));
Ok(ActorResult::Ok)
}
}
fn main() {
let actor_config = TyraConfig::new().unwrap();
let actor_system = ActorSystem::new(actor_config);
let actor = actor_system
.builder()
.spawn("test", TestActorFactory::new())
.unwrap();
actor.send(TestMessage::new()).unwrap();
std::process::exit(actor_system.await_shutdown());
}