batcher

package
v3.8.3 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDataChanSize = 1000
	DefaultSize         = 100
	DefaultBuffer       = 100
	DefaultWorker       = 5
	DefaultInterval     = time.Second
)

Functions

This section is empty.

Types

type Batcher

type Batcher[T any] struct {
	Do         func(ctx context.Context, channelID int, val *Msg[T])
	OnComplete func(lastMessage *T, totalCount int)
	Sharding   func(key string) int
	Key        func(data *T) string
	HookFunc   func(triggerID string, messages map[string][]*T, totalCount int, lastMessage *T)
	// contains filtered or unexported fields
}

func New

func New[T any](opts ...Option) *Batcher[T]

func (*Batcher[T]) Close

func (b *Batcher[T]) Close()

func (*Batcher[T]) Put

func (b *Batcher[T]) Put(ctx context.Context, data *T) error

func (*Batcher[T]) Start

func (b *Batcher[T]) Start() error

func (*Batcher[T]) Worker

func (b *Batcher[T]) Worker() int

type Config

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

type Msg

type Msg[T any] struct {
	// contains filtered or unexported fields
}

func (Msg[T]) Key

func (m Msg[T]) Key() string

func (Msg[T]) String

func (m Msg[T]) String() string

func (Msg[T]) TriggerID

func (m Msg[T]) TriggerID() string

func (Msg[T]) Val

func (m Msg[T]) Val() []*T

type Option

type Option func(c *Config)

func WithBuffer

func WithBuffer(b int) Option

func WithDataBuffer

func WithDataBuffer(size int) Option

func WithInterval

func WithInterval(i time.Duration) Option

func WithSize

func WithSize(s int) Option

func WithSyncWait

func WithSyncWait(wait bool) Option

func WithWorker

func WithWorker(w int) Option

Jump to

Keyboard shortcuts

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