diff --git a/docs/actix/sec-3-address.md b/docs/actix/sec-3-address.md index 0a8723f..33902e2 100644 --- a/docs/actix/sec-3-address.md +++ b/docs/actix/sec-3-address.md @@ -13,6 +13,7 @@ Here is an example of `Actor::start()` method usage. In this example `MyActor` a ```rust struct MyActor; + impl Actor for MyActor { type Context = Context; } @@ -113,7 +114,8 @@ impl Handler for OrderEvents { /// Subscribe to ship message impl Handler for OrderEvents { type Result = (); - fn handle(&mut self, msg: Ship, ctx: &mut Self::Context) -> Self::Result { + + fn handle(&mut self, msg: Ship, ctx: &mut Self::Context) { self.notify(msg.0); System::current().stop(); } @@ -121,25 +123,31 @@ impl Handler for OrderEvents { /// Email Subscriber struct EmailSubscriber; + impl Actor for EmailSubscriber { type Context = Context; } impl Handler for EmailSubscriber { type Result = (); - fn handle(&mut self, msg: OrderShipped, _ctx: &mut Self::Context) -> Self::Result { + + fn handle(&mut self, msg: OrderShipped, _ctx: &mut Self::Context) { println!("Email sent for order {}", msg.0) } } + +/// SMS Subscriber struct SmsSubscriber; + impl Actor for SmsSubscriber { type Context = Context; } impl Handler for SmsSubscriber { type Result = (); - fn handle(&mut self, msg: OrderShipped, _ctx: &mut Self::Context) -> Self::Result { + + fn handle(&mut self, msg: OrderShipped, _ctx: &mut Self::Context) { println!("SMS sent for order {}", msg.0) } @@ -150,9 +158,11 @@ async fn main() -> Result<(), actix::MailboxError> { let email_subscriber = Subscribe(EmailSubscriber {}.start().recipient()); let sms_subscriber = Subscribe(SmsSubscriber {}.start().recipient()); let order_event = OrderEvents::new().start(); + order_event.send(email_subscriber).await?; order_event.send(sms_subscriber).await?; order_event.send(Ship(1)).await?; + Ok(()) } ```