bundler

package
v0.0.0-...-758c02f Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultErrChanCapacity = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Writer

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

Writer is a io.Writer wrapper that uses a bundler to make Write lock-free, non-blocking and thread safe.

func NewWriter

func NewWriter(w io.Writer, opts []WriterOption) *Writer

NewWriter creates a writer wrapping w with a bundler in order to never block the producers and drop writes if the underlying writer can't keep up with the flow of data.

Use a bundler.Writer when

onError := WithOnError(func(err error) {
	   log.Printf("Dropped writes due to: %v", err)
})
wr := NewWriter(w, []WriterOption{onError})
wr.Write([]byte("Hello, World!"))

See https://pkg.go.dev/google.golang.org/api/support/bundler for more info on bundler.

func (*Writer) Close

func (bw *Writer) Close() error

func (*Writer) Write

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

type WriterOption

type WriterOption func(*Writer) bbx.Option

WriterOption can be used to setup the writer.

func WithBufferedByteLimit

func WithBufferedByteLimit(n int) WriterOption

WithBufferedByteLimit sets the maximum number of bytes that the Bundler will keep in memory before returning ErrOverflow. The default is DefaultBufferedByteLimit.

func WithBundleByteLimit

func WithBundleByteLimit(n int) WriterOption

WithBundleByteLimit sets the maximum size of a bundle, in bytes. Zero means unlimited. The default is DefaultBundleByteLimit.

func WithBundleByteThreshold

func WithBundleByteThreshold(n int) WriterOption

WithBundleByteThreshold sets the max size of the bundle (in bytes) at which the bundler is flushed. The default is DefaultBundleByteThreshold.

func WithBundleCountThreshold

func WithBundleCountThreshold(n int) WriterOption

WithBundleCountThreshold sets the max number of items after which the bundler is flushed. The default is DefaultBundleCountThreshold.

func WithDelayThreshold

func WithDelayThreshold(delay time.Duration) WriterOption

WithDelayThreshold sets the interval at which the bundler is flushed. The default is DefaultDelayThreshold.

func WithErrorChannelCapacity

func WithErrorChannelCapacity(n int) WriterOption

WithErrorChannelCapacity sets the buffer capacity of errors channel. The default is DefaultErrChanCapacity.

func WithOnError

func WithOnError(f func(err error)) WriterOption

WithOnError sets the function to be executed on errors. The default is a simple log.

Jump to

Keyboard shortcuts

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