batcher

package
v2.3.62 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 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 {
	MaxSize   int
	BatchTime time.Duration
	// contains filtered or unexported fields
}

func New

func New(maxSize int, batchTime time.Duration) *Batcher

New returns a simple Batcher that can be used to buffer & batch values as simple as this:

b := batcher.New(1024, 5*time.Second)
for {
  select {
    case <- b.Await():
      b.Reset()
      flush(messages)
      messages = nil

    case msg <- kafka.Messages():
      b.Increment()
      messages = append(messages, msg)
  }
}

func (*Batcher) Await

func (b *Batcher) Await() <-chan time.Time

Await the Batcher flush.

func (*Batcher) Increment

func (b *Batcher) Increment()

Increment records a new message in the batch.

func (*Batcher) Reset

func (b *Batcher) Reset()

Reset the Batcher after flushing.

Jump to

Keyboard shortcuts

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