| 45 | type Context = Context<Self>; |
| 46 | |
| 47 | fn started(&mut self, ctx: &mut Self::Context) { |
| 48 | // we'll start heartbeat process on session start. |
| 49 | self.hb(ctx); |
| 50 | |
| 51 | // register self in chat server. `AsyncContext::wait` register |
| 52 | // future within context, but context waits until this future resolves |
| 53 | // before processing any other events. |
| 54 | let addr = ctx.address(); |
| 55 | self.addr |
| 56 | .send(server::Connect { |
| 57 | addr: addr.recipient(), |
| 58 | }) |
| 59 | .into_actor(self) |
| 60 | .then(|res, act, ctx| { |
| 61 | match res { |
| 62 | Ok(res) => act.id = res, |
| 63 | // something is wrong with chat server |
| 64 | _ => ctx.stop(), |
| 65 | } |
| 66 | actix::fut::ready(()) |
| 67 | }) |
| 68 | .wait(ctx); |
| 69 | } |
| 70 | |
| 71 | fn stopping(&mut self, _: &mut Self::Context) -> Running { |
| 72 | // notify chat server |