mercury

package module
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 5 Imported by: 3

README

mercury

Build Status Coverage Status GoDoc Release Go Report Card

An asynchronously flushing buffered writer for Go.

This library implements a simple asynchronously flushing buffered writer by extending the standard bufio.Writer.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stats added in v0.4.0

type Stats struct {
	Initiated uint64
	Executed  uint64
	Extended  uint64
	Cancelled uint64
}

Stats represents runtime statistics of all writers.

func GetStats added in v0.4.0

func GetStats() Stats

GetStats returns general statistics.

func (Stats) Sub added in v0.4.0

func (s Stats) Sub(ss Stats) Stats

Sub will return the difference of the two stats objects.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer extends a buffered writer that executed itself asynchronously. It uses a timer to flush the buffered writer it it gets stale. Errors that occur during the flush are returned on the next call to Write, Flush or WriteAndFlush.

func NewWriter

func NewWriter(w io.Writer, maxDelay time.Duration) *Writer

NewWriter wraps the provided writer and enables buffering and asynchronous flushing using the specified maximum delay.

Note: The delay should not be below 1ms to prevent flushing every write asynchronously.

func NewWriterSize

func NewWriterSize(w io.Writer, maxDelay time.Duration, size int) *Writer

NewWriterSize wraps the provided writer and enables buffering and asynchronous flushing using the specified maximum delay. This method allows configuration of the initial buffer size. Note: The delay should not be below 1ms to prevent flushing every write asynchronously.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush executed the buffered writer immediately.

func (*Writer) SetMaxDelay added in v0.2.0

func (w *Writer) SetMaxDelay(delay time.Duration)

SetMaxDelay can be used to adjust the maximum delay of asynchronous executed.

Note: The delay should not be below 1ms to prevent flushing every write asynchronously.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write implements the io.Writer interface and writes data to the underlying buffered writer and executed it asynchronously.

func (*Writer) WriteAndFlush

func (w *Writer) WriteAndFlush(p []byte) (int, error)

WriteAndFlush writes data to the underlying buffered writer and executed it immediately after writing.

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL