MCPcopy Create free account
hub / github.com/coder/agentapi / notifyChannels

Method notifyChannels

lib/httpapi/events.go:141–161  ·  view source on GitHub ↗

Assumes the caller holds the lock.

(eventType EventType, payload any)

Source from the content-addressed store, hash-verified

139
140// Assumes the caller holds the lock.
141func (e *EventEmitter) notifyChannels(eventType EventType, payload any) {
142 chanIds := make([]int, 0, len(e.chans))
143 for chanId := range e.chans {
144 chanIds = append(chanIds, chanId)
145 }
146 for _, chanId := range chanIds {
147 ch := e.chans[chanId]
148 event := Event{
149 Type: eventType,
150 Payload: payload,
151 }
152
153 select {
154 case ch <- event:
155 default:
156 // If the channel is full, close it.
157 // Listeners must actively drain the channel.
158 e.unsubscribeInner(chanId)
159 }
160 }
161}
162
163// EmitMessages assumes that only the last message can change or new messages can be added.
164// If a new message is injected between existing messages (identified by Id), the behavior is undefined.

Callers 4

EmitMessagesMethod · 0.95
EmitStatusMethod · 0.95
EmitScreenMethod · 0.95
EmitErrorMethod · 0.95

Calls 1

unsubscribeInnerMethod · 0.95

Tested by

no test coverage detected