登录后的sub消息被一个单独的routine处理了
- server/session.go
globals.hub.join <- &sessionJoin{ topic: expanded, //me pkt: msg, // 原始消息 sess: s}
- server/hub.go, 启动了一个单独的goroutine
func newHub() *Hub { ... go h.run() // 在这里面有个go topicInit(t, sreg, h), topic的 ... }
- server/main.go, 在main中就启动了新的goroutine
globals.hub = newHub()
hub对sub消息的处理
- server/hub.go, 把sub的原始消息又塞入了原始消息的topic
me
for { select { case sreg := <-h.join: // 这个sreg在上面的第一步就塞进来了 t := h.topicGet(sreg.topic) if t==nil{ .... }else { t.reg<-sreg // 塞入了原始消息的topic `me` } }
- server/hub.go,启动topic的routine
func (h *Hub) run() { go topicInit(t, sreg, h) }
被topic的routine处理
- server/init_topic.go,
func topicInit(t *Topic, sreg *sessionJoin, h *Hub) { go t.run(h) // 一个topic的循环处理 }
- server/topic.go
func (t *Topic) run(hub *Hub) { ... case sreg := <-t.reg: t.handleSubscription(hub, sreg); // 真正的处理sub消息 ... }