batching

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchWriter

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

BatchWriter will accept messages and invoke the Writer when the batch requirements have been fulfilled (either batch size or interval have been exceeded). BatchWriter should be created with NewBatchWriter().

func NewBatchWriter

func NewBatchWriter(size int, interval time.Duration, writer Writer) *BatchWriter

NewBatchWriter creates a new BatchWriter. For clarity, it is recommenended to use a wrapper type such as NewByteBatchWriter or NewV2EnvelopeBatchWriter vs using this directly.

func (*BatchWriter) Flush

func (b *BatchWriter) Flush()

Flush will write a partial batch if there is data and the interval has lapsed. Otherwise it is a NOP. This method should be called freqently to make sure batches do not stick around for long periods of time.

func (*BatchWriter) ForcedFlush

func (b *BatchWriter) ForcedFlush()

ForcedFlush bypasses the batch interval and batch size checks and writes immediately.

func (*BatchWriter) Write

func (b *BatchWriter) Write(data interface{})

Write stores data to the batch. It will not submit the batch to the writer until either the batch has been filled, or the interval has lapsed.

type Writer

type Writer interface {
	// Write submits the batch.
	Write(batch []interface{})
}

Writer is used to submit the completed batch. The batch may be partial if the interval lapsed instead of filling the batch.

type WriterFunc

type WriterFunc func(batch []interface{})

WriterFunc is an adapter to allow ordinary functions to be a Writer.

func (WriterFunc) Write

func (f WriterFunc) Write(batch []interface{})

Write implements Writer.

Jump to

Keyboard shortcuts

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