extern crate riker; use riker::actors::*; use std::time::Duration; #[derive(Default)] struct Child; impl Actor for Child { type Msg = String; fn recv(&mut self, _ctx: &Context, msg: Self::Msg, _sender: Sender) { println!("child got a message {}", msg); } } #[derive(Default)] struct MyActor { child: Option>, } // implement the Actor trait impl Actor for MyActor { type Msg = String; fn pre_start(&mut self, ctx: &Context) { self.child = Some(ctx.actor_of::("my-child").unwrap()); } fn recv(&mut self, _ctx: &Context, msg: Self::Msg, sender: Sender) { println!("parent got a message {}", msg); self.child.as_ref().unwrap().tell(msg, sender); } } // start the system and create an actor fn main() { let sys = ActorSystem::new().unwrap(); let my_actor = sys.actor_of::("my-actor").unwrap(); my_actor.tell("Hello my actor!".to_string(), None); println!("Child not added yet"); sys.print_tree(); println!("Child added already"); std::thread::sleep(Duration::from_millis(500)); sys.print_tree(); }