SyncWriter wraps w so that each call to Write is synchronized with a mutex. This syncer can be used to wrap the call to writer's Write method if it is not thread safe. Note that you do not need this wrapper for os.File Write operations on POSIX and Windows systems as they are already thread-safe.
(w io.Writer)
| 46 | // not thread safe. Note that you do not need this wrapper for os.File Write |
| 47 | // operations on POSIX and Windows systems as they are already thread-safe. |
| 48 | func SyncWriter(w io.Writer) io.Writer { |
| 49 | if lw, ok := w.(LevelWriter); ok { |
| 50 | return &syncWriter{lw: lw} |
| 51 | } |
| 52 | return &syncWriter{lw: LevelWriterAdapter{w}} |
| 53 | } |
| 54 | |
| 55 | // Write implements the io.Writer interface. |
| 56 | func (s *syncWriter) Write(p []byte) (n int, err error) { |
no outgoing calls