dynworker

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Default minimum worker count.
	DefaultMinimumWorkerCount int32 = 1

	// Default maximum worker count.
	DefaultMaximumWorkerCount int32 = 10

	// Default worker count multipler.
	//
	// This is used when there is an invalid maximum worker count.
	DefaultWorkerCountMult int32 = 4

	// Default worker timeout.
	DefaultTimeout time.Duration = 30 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name        string          // Worker pool name for logger and metrics.
	MinWorkers  int32           // Minimum number of workers.
	MaxWorkers  int32           // Maximum number of workers.
	Logger      logger.Logger   // Logger instance.
	Parent      context.Context // Parent context.
	IdleTimeout time.Duration   // Idle timeout duration.
}

func NewConfig

func NewConfig(
	ctx context.Context,
	lgr logger.Logger,
	name string,
	minw, maxw int32,
) *Config

Create a new configuration.

func NewDefaultConfig

func NewDefaultConfig() *Config

Create a new default configuration.

func (*Config) SetItleTimeout

func (obj *Config) SetItleTimeout(timeout time.Duration)

Set the idle timeout value.

type Task

type Task any

Task data type.

type TaskFn

type TaskFn func(Task) error

Type of functions executed by workers.

type WorkerPool

type WorkerPool interface {
	// Start the worker pool.
	Start()

	// Stop the worker pool.
	Stop()

	// Submit a task to the worker pool.
	Submit(Task) error

	// Return the number of current workers in the pool.
	WorkerCount() int32

	// Return the minimum number of workers in the pool.
	MinWorkers() int32

	// Return the maximum number of workers in the pool.
	MaxWorkers() int32
}

Worker pool interface

func NewWorkerPool

func NewWorkerPool(config *Config, workfn TaskFn) WorkerPool

Create a new worker pool.

Jump to

Keyboard shortcuts

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