func (s *Server) subHandler(w http.ResponseWriter, r *http.Request) { queues_param := r.FormValue("queues") var queues []string if len(queues_param) > 0 { queues = strings.Split(queues_param, ",") } sub := hub.NewSubscription(queues) finished := make(chan struct{}) defer close(finished) disconnected := w.(http.CloseNotifier).CloseNotify() go func() { select { case <-disconnected: case <-finished: } sub.Close() }() go s.hub.Sub(sub) if res, ok := <-sub.Result(); ok { w.Header().Set("Queue", res.Queue) w.Write(res.Message) counts.Add("SubCount", 1) counts.Add("SubBs", int64(len(res.Message))) } }
func (s *Server) subHandler(w http.ResponseWriter, r *http.Request) { queues := strings.Split(r.FormValue("queues"), ",") sub := hub.NewSubscription(queues) finished := make(chan struct{}) defer close(finished) disconnected := w.(http.CloseNotifier).CloseNotify() go func() { select { case <-disconnected: case <-finished: } sub.Close() }() go s.hub.Sub(sub) if res, ok := <-sub.Result(); ok { w.Header().Set("Queue", res.Queue) w.Write(res.Message) } }