channelx

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregator

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

Aggregator 聚合器结构体

func NewAggregator

func NewAggregator(batchProcessor BatchProcessFunc, optionFuncs ...SetAggregatorOptionFunc) (*Aggregator, error)

NewAggregator 创建新的聚合器实例

func (*Aggregator) Enqueue

func (agt *Aggregator) Enqueue(item interface{}) error

Enqueue 入队一个项目,会阻塞直到有空间

func (*Aggregator) EnqueueWithRetry

func (agt *Aggregator) EnqueueWithRetry(item interface{}, maxRetries int, backoff time.Duration) bool

EnqueueWithRetry 入队一个项目,会重试直到成功或者达到最大重试次数

func (*Aggregator) SafeStop

func (agt *Aggregator) SafeStop()

SafeStop 安全停止聚合器,确保所有项目都被处理

func (*Aggregator) Start

func (agt *Aggregator) Start()

Start 启动聚合器

func (*Aggregator) Stop

func (agt *Aggregator) Stop()

Stop 停止聚合器

func (*Aggregator) TryEnqueue

func (agt *Aggregator) TryEnqueue(item interface{}) bool

TryEnqueue 尝试入队一个项目,非阻塞

type AggregatorOption

type AggregatorOption struct {
	BatchSize         int
	Workers           int
	ChannelBufferSize int
	LingerTime        time.Duration
	ErrorHandler      ErrorHandlerFunc
	Logger            *log.Logger
}

AggregatorOption 聚合器选项

type BatchProcessFunc

type BatchProcessFunc func([]interface{}) error

BatchProcessFunc 批处理函数类型

type ErrorHandlerFunc

type ErrorHandlerFunc func(err error, items []interface{}, batchProcessFunc BatchProcessFunc, aggregator *Aggregator)

ErrorHandlerFunc 错误处理函数类型

type SetAggregatorOptionFunc

type SetAggregatorOptionFunc func(option *AggregatorOption)

SetAggregatorOptionFunc 聚合器选项设置函数类型

func WithBatchSize

func WithBatchSize(batchSize int) SetAggregatorOptionFunc

示例: 设置聚合器选项的函数

func WithChannelBufferSize

func WithChannelBufferSize(size int) SetAggregatorOptionFunc

func WithErrorHandler

func WithErrorHandler(handler ErrorHandlerFunc) SetAggregatorOptionFunc

func WithLingerTime

func WithLingerTime(duration time.Duration) SetAggregatorOptionFunc

func WithLogger

func WithLogger(logger *log.Logger) SetAggregatorOptionFunc

func WithWorkers

func WithWorkers(workers int) SetAggregatorOptionFunc

Jump to

Keyboard shortcuts

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