Documentation ¶
Index ¶
Constants ¶
const ( // DefaultBatchSize is the default batch size. DefaultBatchSize = 100 // DefaultFlushInterval is the default flush interval. DefaultFlushInterval = time.Second )
Variables ¶
This section is empty.
Functions ¶
func WithFlushInterval ¶
WithFlushInterval sets flush interval.
Types ¶
type Batcher ¶
type Batcher struct { BatchSize int FlushInterval time.Duration // contains filtered or unexported fields }
Batcher accumulate messages in an internal buffer and flushes it if it is full or flush interval is expired.
func New ¶
New creates a new batcher with defined Flusher and options. If Flusher is nil, then Batcher panic.
func (*Batcher) Put ¶
func (b *Batcher) Put(v interface{})
Put accumulate value into internal buffer.
func (*Batcher) Recuperate ¶
func (b *Batcher) Recuperate(batch []interface{})
Recuperate the a batch slice fo reusing. Recuperation extremely decrease memory allocations.
type Flusher ¶
type Flusher interface {
Flush(batch []interface{}) (recuperate bool)
}
Flusher describes the interface of the batch flusher.
type FlusherFunc ¶
type FlusherFunc func(batch []interface{})
FlusherFunc implements the Flusher interface for the flushing function. Batch slice is recuperated automatically after returning.
func (FlusherFunc) Flush ¶
func (f FlusherFunc) Flush(batch []interface{}) (recuperate bool)
Flush the batch.
type FlusherNoRecuperateFunc ¶
type FlusherNoRecuperateFunc func(batch []interface{})
FlusherNoRecuperateFunc implements the Flusher interface for the flushing function. The batch slice will not be recuperated. However it can be recuperated later with Batcher.Recuperate function.
func (FlusherNoRecuperateFunc) Flush ¶
func (f FlusherNoRecuperateFunc) Flush(batch []interface{}) (recuperate bool)
Flush the batch.