batcher

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2016 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDisposed = errors.New("batcher: disposed")

ErrDisposed is the error returned for a disposed Batcher

Functions

This section is empty.

Types

type Batcher

type Batcher interface {
	// Put adds items to the batcher.
	Put(interface{}) error

	// Get retrieves a batch from the batcher. This call will block until
	// one of the conditions for a "complete" batch is reached.
	Get() ([]interface{}, error)

	// Flush forcibly completes the batch currently being built
	Flush() error

	// Dispose will dispose of the batcher. Any calls to Put or Flush
	// will return ErrDisposed, calls to Get will return an error iff
	// there are no more ready batches.
	Dispose()

	// IsDisposed will determine if the batcher is disposed
	IsDisposed() bool
}

Batcher provides an API for accumulating items into a batch for processing.

func New

func New(maxTime time.Duration, maxItems, maxBytes, queueLen uint, calculate CalculateBytes) (Batcher, error)

New creates a new Batcher using the provided arguments. Batch readiness can be determined in three ways:

  • Maximum number of bytes per batch
  • Maximum number of items per batch
  • Maximum amount of time waiting for a batch

Values of zero for one of these fields indicate they should not be taken into account when evaluating the readiness of a batch. This provides an ordering guarantee for any given thread such that if a thread places two items in the batcher, Get will guarantee the first item is returned before the second, whether before the second in the same batch, or in an earlier batch.

type CalculateBytes

type CalculateBytes func(interface{}) uint

CalculateBytes evaluates the number of bytes in an item added to a Batcher.

Jump to

Keyboard shortcuts

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