MCPcopy
hub / github.com/nats-io/nats.go / sendStatusEvent

Method sendStatusEvent

nats.go:5139–5159  ·  view source on GitHub ↗

sendStatusEvent sends subscription status event to all channels. If there is no listener, sendStatusEvent will not block. Lock should be held entering.

(status SubStatus)

Source from the content-addressed store, hash-verified

5137// If there is no listener, sendStatusEvent
5138// will not block. Lock should be held entering.
5139func (s *Subscription) sendStatusEvent(status SubStatus) {
5140 for ch, statuses := range s.statListeners {
5141 if !slices.Contains(statuses, status) {
5142 continue
5143 }
5144 // only send event if someone's listening
5145 select {
5146 case ch <- status:
5147 default:
5148 }
5149 }
5150 // After sending SubscriptionClosed status to all listeners,
5151 // close all channels and clear the map to prevent future
5152 // sends to closed channels that could cause panics
5153 if status == SubscriptionClosed {
5154 for ch := range s.statListeners {
5155 close(ch)
5156 }
5157 s.statListeners = nil
5158 }
5159}
5160
5161// changeSubStatus changes subscription status and sends events
5162// to all listeners. Lock should be held entering.

Callers 1

changeSubStatusMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected