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

@ -232,8 +232,8 @@ type transA struct {
closed atomic.Bool
closeErr error
currentReader io.Reader
currentWriter io.Closer
currentReader io.Reader
currentWriter usync.Monitor[io.Closer]
deadline *time.Timer
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) {
currentWriter, done := this.currentWriter.BorrowReturn()
defer done(&currentWriter)
// close previous writer if necessary
if this.currentWriter != nil {
this.currentWriter.Close()
this.currentWriter = nil
if currentWriter != nil {
currentWriter.Close()
currentWriter = nil
}
// create new writer
@ -284,7 +287,7 @@ func (this *transA) SendWriter(method uint16) (io.WriteCloser, error) {
chunkSize: defaultChunkSize,
open: true,
}
this.currentWriter = writer
currentWriter = writer
return writer, nil
}