Files
coder/scaletest/loadtestutil/syncwriter.go
2022-12-15 15:04:24 +00:00

27 lines
415 B
Go

package loadtestutil
import (
"io"
"sync"
)
// SyncWriter wraps an io.Writer in a sync.Mutex.
type SyncWriter struct {
mut *sync.Mutex
w io.Writer
}
func NewSyncWriter(w io.Writer) *SyncWriter {
return &SyncWriter{
mut: &sync.Mutex{},
w: w,
}
}
// Write implements io.Writer.
func (sw *SyncWriter) Write(p []byte) (n int, err error) {
sw.mut.Lock()
defer sw.mut.Unlock()
return sw.w.Write(p)
}