METADAPT-A writing is goroutine safe
This commit is contained in:
parent
cdda4f932d
commit
c5073e5f20
15
metadapta.go
15
metadapta.go
@ -232,8 +232,8 @@ type transA struct {
|
|||||||
closed atomic.Bool
|
closed atomic.Bool
|
||||||
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(¤tWriter)
|
||||||
|
|
||||||
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user