Documentation
¶
Index ¶
Constants ¶
View Source
const DefaultQueueSize = 1 << 8
View Source
const DefaultWorkerNumber = 1
Variables ¶
This section is empty.
Functions ¶
func GetWorkerIndex ¶ added in v0.0.4
GetWorkerIndex retrieves the worker index from the context. If the index is not set, it returns -1
Types ¶
type ContextKey ¶ added in v0.0.4
type ContextKey string
const (
CtxKeyWorkerIdx ContextKey = "_worker_idx"
)
type Hive ¶
type Hive[T any] struct { // contains filtered or unexported fields }
Hive is a worker pool that can handle data concurrently
func NewHive ¶
func NewHive[T any](config *HiveConfig) *Hive[T]
NewHive create a worker pool with a given config, if config is nil, use NewConfig()
func (*Hive[T]) Push ¶
func (h *Hive[T]) Push(data T)
Push data into the hive, if the hive is closed, it will panic
func (*Hive[T]) SetHandler ¶
SetHandler set the handler for the hive, if not set, it will panic when push data into the hive
type HiveConfig ¶
HiveConfig is the config for the hive
func (*HiveConfig) WithLogger ¶
func (h *HiveConfig) WithLogger(logger Logger) *HiveConfig
WithLogger set the logger, default is NoLog
func (*HiveConfig) WithQueueSize ¶
func (h *HiveConfig) WithQueueSize(queueSize int) *HiveConfig
WithQueueSize set the size of the queue, default is 256
func (*HiveConfig) WithWorkerNumber ¶
func (h *HiveConfig) WithWorkerNumber(workerNumber int) *HiveConfig
WithWorkerNumber set the number of workers, default is 1
Click to show internal directories.
Click to hide internal directories.