METADAPT-A writing is goroutine safe

This commit is contained in:
Sasha Koshka 2025-11-19 20:55:57 -05:00
parent cdda4f932d
commit c5073e5f20

View File

@ -233,7 +233,7 @@ type transA struct {
closeErr error closeErr error
currentReader io.Reader currentReader io.Reader
currentWriter io.Closer currentWriter usync.Monitor[io.Closer]
deadline *time.Timer deadline *time.Timer
deadlineLock sync.Mutex deadlineLock sync.Mutex
@ -270,10 +270,13 @@ func (this *transA) Send(method uint16, data []byte) error {
} }
func (this *transA) SendWriter(method uint16) (io.WriteCloser, error) { func (this *transA) SendWriter(method uint16) (io.WriteCloser, error) {
currentWriter, done := this.currentWriter.BorrowReturn()
defer done(&currentWriter)
// close previous writer if necessary // close previous writer if necessary
if this.currentWriter != nil { if currentWriter != nil {
this.currentWriter.Close() currentWriter.Close()
this.currentWriter = nil currentWriter = nil
} }
// create new writer // create new writer
@ -284,7 +287,7 @@ func (this *transA) SendWriter(method uint16) (io.WriteCloser, error) {
chunkSize: defaultChunkSize, chunkSize: defaultChunkSize,
open: true, open: true,
} }
this.currentWriter = writer currentWriter = writer
return writer, nil return writer, nil
} }