METADAPT-A writing is goroutine safe
This commit is contained in:
parent
cdda4f932d
commit
c5073e5f20
13
metadapta.go
13
metadapta.go
@ -233,7 +233,7 @@ type transA struct {
|
||||
closeErr error
|
||||
|
||||
currentReader io.Reader
|
||||
currentWriter io.Closer
|
||||
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(¤tWriter)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user