Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrClosed = errors.New("buffered_writer: closed")
)
Functions ¶
This section is empty.
Types ¶
type BufferedWriter ¶
type BufferedWriter struct {
// contains filtered or unexported fields
}
func NewBufferedWriter ¶
func NewBufferedWriter(w WriteFlusher, bufferSize int) *BufferedWriter
func (*BufferedWriter) Close ¶
func (b *BufferedWriter) Close() error
Close closes the writer and prevents any new writes from succeeding. This does not close the underlying writer which must be closed to ensure any pending writes are canceled. It must be safe to close the underlying writer from a different goroutine than an active Write.
Close does not block.
func (*BufferedWriter) Flush ¶
func (b *BufferedWriter) Flush() error
type PipelinedFlushWriter ¶
type PipelinedFlushWriter struct {
// contains filtered or unexported fields
}
PipelinedFlushWriter is a writer that serialises and batches parallel writes, similar to Writer, but with two additional properties:
- Flush is performed after every Write.
- Flush and Write are pipelined, so that a Flush may occur in parallel with a Write, but Writes are serialised, and Flushes are serialised.
This behaviour is particularly useful for write-ahead logs, where the caller wants to ensure writes are flushed to disk, but also wants to do many writes in parallel for high total throughput.
func NewPipelinedFlushWriter ¶
func NewPipelinedFlushWriter(wf WriteFlusher) *PipelinedFlushWriter
type WriteFlusher ¶
func NopFlusher ¶
func NopFlusher(w io.Writer) WriteFlusher
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer serialises and batches concurrent writes, to minimise Write calls to the underlying io.Writer. This is useful when the underlying io.Writer has properties that make each Write expensive, such as sending across a network and waiting for an ack, or flushing after every write. If your io.Writer does not have this property, you should instead synchronize using a sync.Mutex.