MCPcopy Index your code
hub / github.com/the-open-agent/openagent / streamMessageAnswerJob

Function streamMessageAnswerJob

controllers/message_answer.go:100–138  ·  view source on GitHub ↗
(responseWriter http.ResponseWriter, request *http.Request, job *messageAnswerJob)

Source from the content-addressed store, hash-verified

98}
99
100func streamMessageAnswerJob(responseWriter http.ResponseWriter, request *http.Request, job *messageAnswerJob) {
101 replay, ch, unsubscribe, done := job.subscribe()
102 defer unsubscribe()
103
104 for _, chunk := range replay {
105 if _, err := responseWriter.Write(chunk); err != nil {
106 return
107 }
108 if flusher, ok := responseWriter.(http.Flusher); ok {
109 flusher.Flush()
110 }
111 }
112
113 if done {
114 return
115 }
116
117 var notify <-chan struct{}
118 if request != nil {
119 notify = request.Context().Done()
120 }
121
122 for {
123 select {
124 case chunk, ok := <-ch:
125 if !ok {
126 return
127 }
128 if _, err := responseWriter.Write(chunk); err != nil {
129 return
130 }
131 if flusher, ok := responseWriter.(http.Flusher); ok {
132 flusher.Flush()
133 }
134 case <-notify:
135 return
136 }
137 }
138}
139
140func generateMessageAnswer(id string, responseWriter http.ResponseWriter, host string, lang string, signedIn bool, responseError func(string, ...interface{})) {
141 responseErrorStream := func(message *object.Message, errorText string) {

Callers 1

GetMessageAnswerMethod · 0.85

Calls 4

subscribeMethod · 0.80
ContextMethod · 0.65
WriteMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected