Documentation
¶
Overview ¶
Package gbuffer provides generic batching, aggregation, and priority worker scheduling.
Index ¶
- Variables
- func SumInt64(old, next int64) int64
- type AddFunc
- type AddMiddleware
- type AggregateAddFunc
- type AggregateAddMiddleware
- type Aggregator
- type AggregatorOption
- func WithAggregatorFlushInterval[K comparable, V any](d time.Duration) AggregatorOption[K, V]
- func WithAggregatorOnError[K comparable, V any](onError func(error)) AggregatorOption[K, V]
- func WithAggregatorPool[K comparable, V any](pool WorkerPool) AggregatorOption[K, V]
- func WithAggregatorPriority[K comparable, V any](priority int) AggregatorOption[K, V]
- func WithEventThreshold[K comparable, V any](n int) AggregatorOption[K, V]
- func WithKeyThreshold[K comparable, V any](n int) AggregatorOption[K, V]
- type Batcher
- type BatcherOption
- func WithBatchFlushInterval[T any](d time.Duration) BatcherOption[T]
- func WithBatchMaxPending[T any](n int) BatcherOption[T]
- func WithBatchOnError[T any](onError func(error)) BatcherOption[T]
- func WithBatchPool[T any](pool WorkerPool) BatcherOption[T]
- func WithBatchPriority[T any](priority int) BatcherOption[T]
- func WithBatchSinkMiddleware[T any](middleware ...Middleware[[]T]) BatcherOption[T]
- func WithBatchSize[T any](size int) BatcherOption[T]
- type Combiner
- type Job
- type Middleware
- type PoolOption
- type PriorityWorkerPool
- type SinkJob
- type Sinker
- type WorkerPool
Constants ¶
This section is empty.
Variables ¶
Functions ¶
Types ¶
type AddMiddleware ¶
type AggregateAddFunc ¶
type AggregateAddFunc[K comparable, V any] func(context.Context, K, V) error
type AggregateAddMiddleware ¶
type AggregateAddMiddleware[K comparable, V any] func(AggregateAddFunc[K, V]) AggregateAddFunc[K, V]
type Aggregator ¶
type Aggregator[K comparable, V any] struct { // contains filtered or unexported fields }
func NewAggregator ¶
func NewAggregator[K comparable, V any](sink Sinker[map[K]V], combine Combiner[V], opts ...AggregatorOption[K, V]) (*Aggregator[K, V], error)
NewAggregator returns an Aggregator. combine must not call back into the aggregator: it runs while the internal mutex is held and re-entrant Add or Flush calls will deadlock.
func (*Aggregator[K, V]) Add ¶
func (a *Aggregator[K, V]) Add(ctx context.Context, key K, value V) error
func (*Aggregator[K, V]) Close ¶
func (a *Aggregator[K, V]) Close(ctx context.Context) error
Close stops accepting items, waits for the periodic flush loop to exit, performs a final flush, and then waits for all pooled flushes submitted before Close started to finish running. If ctx is cancelled during the final flush or the wait, ctx.Err() is returned.
type AggregatorOption ¶
type AggregatorOption[K comparable, V any] func(*Aggregator[K, V])
func WithAggregatorFlushInterval ¶
func WithAggregatorFlushInterval[K comparable, V any](d time.Duration) AggregatorOption[K, V]
func WithAggregatorOnError ¶ added in v0.2.0
func WithAggregatorOnError[K comparable, V any](onError func(error)) AggregatorOption[K, V]
WithAggregatorOnError installs a callback invoked for errors that occur outside of explicit Flush calls (the periodic flush loop). A nil callback drops errors. The callback runs on the flush loop goroutine: it must not call Close or Flush on the same Aggregator, or it will deadlock.
func WithAggregatorPool ¶
func WithAggregatorPool[K comparable, V any](pool WorkerPool) AggregatorOption[K, V]
func WithAggregatorPriority ¶
func WithAggregatorPriority[K comparable, V any](priority int) AggregatorOption[K, V]
func WithEventThreshold ¶
func WithEventThreshold[K comparable, V any](n int) AggregatorOption[K, V]
func WithKeyThreshold ¶
func WithKeyThreshold[K comparable, V any](n int) AggregatorOption[K, V]
type Batcher ¶
type Batcher[T any] struct { // contains filtered or unexported fields }
func NewBatcher ¶
func NewBatcher[T any](sink Sinker[[]T], opts ...BatcherOption[T]) (*Batcher[T], error)
type BatcherOption ¶
func WithBatchFlushInterval ¶
func WithBatchFlushInterval[T any](d time.Duration) BatcherOption[T]
func WithBatchMaxPending ¶
func WithBatchMaxPending[T any](n int) BatcherOption[T]
WithBatchMaxPending caps how many undrained items may sit in the internal batch; Add returns ErrFull beyond it. Note: if maxPending < batchSize and no flush interval is configured, Add will report ErrFull before a size-based flush can trigger — pair such configs with WithBatchFlushInterval.
func WithBatchOnError ¶ added in v0.2.0
func WithBatchOnError[T any](onError func(error)) BatcherOption[T]
WithBatchOnError installs a callback invoked for errors that occur outside of explicit Flush calls (the periodic flush loop). A nil callback drops errors. The callback runs on the flush loop goroutine: it must not call Close or Flush on the same Batcher, or it will deadlock.
func WithBatchPool ¶
func WithBatchPool[T any](pool WorkerPool) BatcherOption[T]
func WithBatchPriority ¶
func WithBatchPriority[T any](priority int) BatcherOption[T]
func WithBatchSinkMiddleware ¶
func WithBatchSinkMiddleware[T any](middleware ...Middleware[[]T]) BatcherOption[T]
func WithBatchSize ¶
func WithBatchSize[T any](size int) BatcherOption[T]
type Middleware ¶
type PoolOption ¶
type PoolOption func(*PriorityWorkerPool)
func WithQueueSize ¶
func WithQueueSize(n int) PoolOption
func WithWorkers ¶
func WithWorkers(n int) PoolOption
type PriorityWorkerPool ¶
type PriorityWorkerPool struct {
// contains filtered or unexported fields
}
func NewPriorityWorkerPool ¶
func NewPriorityWorkerPool(opts ...PoolOption) *PriorityWorkerPool
func (*PriorityWorkerPool) Close ¶
func (p *PriorityWorkerPool) Close(ctx context.Context) error
Close stops accepting new jobs and waits for queued and running jobs to finish, returning every collected job error joined into one error (errors.Join). If ctx is cancelled first, it returns ctx.Err() while workers keep draining.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
aggregator
command
|
|
|
batcher
command
|
|
|
close_flush
command
|
|
|
middleware
command
|
|
|
shared_pool
command
|