You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

26 lines
376 B

package syncio
import (
"io"
"sync"
)
// Reader is synchronized io.Reader.
type Reader struct {
r io.Reader
mux sync.Mutex
}
// NewReader creates new Reader.
func NewReader(r io.Reader) *Reader {
return &Reader{r: r}
}
// Read implements io.Reader.
func (s *Reader) Read(p []byte) (n int, err error) {
s.mux.Lock()
n, err = s.r.Read(p)
s.mux.Unlock()
return
}