batching

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batcher

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

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

func NewBatcher

func NewBatcher(size int, interval time.Duration, writer Writer) *Batcher

NewBatcher creates a new Batcher. It is recommenended to use a wrapper type such as NewByteBatcher or NewV2EnvelopeBatcher vs using this directly.

func (*Batcher) Flush

func (b *Batcher) 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. As a result it would be a bad idea to call Flush after an operation that might block for an un-specified amount of time. NOTE: Flush is *not* thread safe and should be called by the same goroutine that calls Write.

func (*Batcher) ForcedFlush

func (b *Batcher) ForcedFlush()

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

func (*Batcher) Write

func (b *Batcher) 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. NOTE: Write is *not* thread safe and should be called by the same goroutine that calls Flush.

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