MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / writerLoop

Method writerLoop

pkg/web/sse/ssehandler.go:134–166  ·  view source on GitHub ↗

writerLoop handles all writes and keepalives in a single goroutine

()

Source from the content-addressed store, hash-verified

132
133// writerLoop handles all writes and keepalives in a single goroutine
134func (h *SSEHandlerCh) writerLoop() {
135 defer h.wg.Done()
136 defer h.runOnCloseHandlers()
137
138 keepaliveTicker := time.NewTicker(SSEKeepaliveInterval)
139 defer keepaliveTicker.Stop()
140
141 for {
142 select {
143 case msg, ok := <-h.writeCh:
144 if !ok {
145 // Channel closed, send [DONE] and exit
146 h.writeDirectly("[DONE]", SSEMsgData)
147 return
148 }
149
150 if err := h.writeMessage(msg); err != nil {
151 h.setError(err)
152 return
153 }
154
155 case <-keepaliveTicker.C:
156 if err := h.writeDirectly("keepalive", SSEMsgComment); err != nil {
157 h.setError(err)
158 return
159 }
160
161 case <-h.ctx.Done():
162 h.setError(h.ctx.Err())
163 return
164 }
165 }
166}
167
168// writeMessage writes a message to the SSE stream
169func (h *SSEHandlerCh) writeMessage(msg SSEMessage) error {

Callers 1

SetupSSEMethod · 0.95

Calls 6

runOnCloseHandlersMethod · 0.95
writeDirectlyMethod · 0.95
writeMessageMethod · 0.95
setErrorMethod · 0.95
ErrMethod · 0.80
StopMethod · 0.65

Tested by

no test coverage detected