MCPcopy Create free account
hub / github.com/actix/examples / started

Method started

websockets/chat/src/session.rs:64–88  ·  view source on GitHub ↗

Method is called on actor start. We register ws session with ChatServer

(&mut self, ctx: &mut Self::Context)

Source from the content-addressed store, hash-verified

62 /// Method is called on actor start.
63 /// We register ws session with ChatServer
64 fn started(&mut self, ctx: &mut Self::Context) {
65 // we'll start heartbeat process on session start.
66 self.hb(ctx);
67
68 // register self in chat server. `AsyncContext::wait` register
69 // future within context, but context waits until this future resolves
70 // before processing any other events.
71 // HttpContext::state() is instance of WsChatSessionState, state is shared
72 // across all routes within application
73 let addr = ctx.address();
74 self.addr
75 .send(server::Connect {
76 addr: addr.recipient(),
77 })
78 .into_actor(self)
79 .then(|res, act, ctx| {
80 match res {
81 Ok(res) => act.id = res,
82 // something is wrong with chat server
83 _ => ctx.stop(),
84 }
85 fut::ready(())
86 })
87 .wait(ctx);
88 }
89
90 fn stopping(&mut self, _: &mut Self::Context) -> Running {
91 // notify chat server

Callers

nothing calls this directly

Calls 3

waitMethod · 0.80
stopMethod · 0.80
hbMethod · 0.45

Tested by

no test coverage detected