MCPcopy
hub / github.com/wavetermdev/waveterm / CloseWithError

Method CloseWithError

pkg/streamclient/streamwriter.go:176–207  ·  view source on GitHub ↗

If CloseWithError() is called while a Write is blocked, the Write will return an error and buffered data may be discarded.

(err error)

Source from the content-addressed store, hash-verified

174
175// If CloseWithError() is called while a Write is blocked, the Write will return an error and buffered data may be discarded.
176func (w *Writer) CloseWithError(err error) error {
177 w.lock.Lock()
178 defer w.lock.Unlock()
179
180 if w.closed {
181 return nil
182 }
183
184 w.closed = true
185 if w.err == nil {
186 w.err = io.ErrClosedPipe
187 }
188 w.cond.Broadcast()
189
190 var dataPk wshrpc.CommandStreamData
191 if err == nil || err == io.EOF {
192 dataPk = wshrpc.CommandStreamData{
193 Id: w.id,
194 Seq: w.nextSeq,
195 Eof: true,
196 }
197 } else {
198 dataPk = wshrpc.CommandStreamData{
199 Id: w.id,
200 Seq: w.nextSeq,
201 Error: err.Error(),
202 }
203 }
204 w.dataSender.SendData(dataPk)
205
206 return nil
207}

Callers 4

TestErrorFunction · 0.95
CloseMethod · 0.95
TestBrokerErrorFunction · 0.80

Calls 2

SendDataMethod · 0.65
ErrorMethod · 0.45

Tested by 2

TestErrorFunction · 0.76
TestBrokerErrorFunction · 0.64