If CloseWithError() is called while a Write is blocked, the Write will return an error and buffered data may be discarded.
(err error)
| 174 | |
| 175 | // If CloseWithError() is called while a Write is blocked, the Write will return an error and buffered data may be discarded. |
| 176 | func (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 | } |