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 (*Config) SetItleTimeout ¶
Set the idle timeout value.
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.
Click to show internal directories.
Click to hide internal directories.