Advertisement
Guest User

Untitled

a guest
Jul 11th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.88 KB | None | 0 0
  1. impl Actor for Watcher {
  2.  
  3.     fn pre_start(&mut self, ctx: ActorContext) {
  4.  
  5.         // Registers target actor as watched
  6.         ctx.system().watch(&ctx.self_, &self.target);
  7.     }
  8.  
  9.     fn post_stop(&mut self, ctx: ActorContext) {
  10.  
  11.         // Unregisters target actor as watched
  12.         ctx.system().unwatch(&ctx.self_, &self.target);
  13.     }
  14.  
  15.     fn receive(self: &mut Self, msg: Message, ctx: ActorContext) -> HandleResult {
  16.         match_downcast_ref!(msg.get(), {
  17.             _m: Terminated => {
  18.                 // Sender of this message is the target actor. It indicates that the target actor was
  19.                 // stopped
  20.                 if ctx.sender.path() == self.target.path() {
  21.                     println!("Target actor '{}' was terminated", ctx.sender);
  22.                 }
  23.             },
  24.             _ => return Ok(false)
  25.         });
  26.  
  27.         Ok(true)
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement