batcher

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README

batcher GoDoc Go Report Card

batcher collect a data and flush it if the batch is full or the interval is elapsed.

Installation

go get github.com/gotidy/batcher

Examples

batch := New(flusher)
batch.Put("some data")

Documentation

GoDoc

License

Apache 2.0

Documentation

Index

Constants

View Source
const (
	DefaultBatchSize     = 100
	DefaultFlushInterval = time.Second
)

Variables

This section is empty.

Functions

func WithBatchSize

func WithBatchSize(size int) func(*Batcher)

func WithFlushInterval

func WithFlushInterval(interval time.Duration) func(*Batcher)

Types

type Batcher

type Batcher struct {
	BatchSize     int
	FlushInterval time.Duration
	// contains filtered or unexported fields
}

func New

func New(f Flusher, opts ...Option) *Batcher

func (*Batcher) Close

func (b *Batcher) Close()

func (*Batcher) Put

func (b *Batcher) Put(v interface{})

func (*Batcher) Recuperate

func (b *Batcher) Recuperate(batch []interface{})

type Flusher

type Flusher interface {
	Flush(batch []interface{}) (recuperate bool)
}

type Option

type Option func(*Batcher)

Jump to

Keyboard shortcuts

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