publish publishes the msg to all subscribers. It never blocks and so messages to slow subscribers are dropped.
(msg []byte)
| 161 | // It never blocks and so messages to slow subscribers |
| 162 | // are dropped. |
| 163 | func (cs *chatServer) publish(msg []byte) { |
| 164 | cs.subscribersMu.Lock() |
| 165 | defer cs.subscribersMu.Unlock() |
| 166 | |
| 167 | cs.publishLimiter.Wait(context.Background()) |
| 168 | |
| 169 | for s := range cs.subscribers { |
| 170 | select { |
| 171 | case s.msgs <- msg: |
| 172 | default: |
| 173 | go s.closeSlow() |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | // addSubscriber registers a subscriber. |
| 179 | func (cs *chatServer) addSubscriber(s *subscriber) { |