MCPcopy
hub / github.com/coder/websocket / publish

Method publish

internal/examples/chat/chat.go:163–176  ·  view source on GitHub ↗

publish publishes the msg to all subscribers. It never blocks and so messages to slow subscribers are dropped.

(msg []byte)

Source from the content-addressed store, hash-verified

161// It never blocks and so messages to slow subscribers
162// are dropped.
163func (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.
179func (cs *chatServer) addSubscriber(s *subscriber) {

Callers 1

publishHandlerMethod · 0.95

Calls 1

LockMethod · 0.45

Tested by

no test coverage detected