Documentation
¶
Index ¶
Constants ¶
View Source
const ( HighPriority = 2 MediumPriority = 1 LowPriority = 0 )
Priority levels
Variables ¶
View Source
var ( ErrPoolClosed = errors.New("worker pool is closed") ErrTaskTimeout = errors.New("task timed out") ErrQueueFull = errors.New("task queue is full") ErrInvalidPriority = errors.New("invalid task priority") )
Error definitions
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*WorkerPool)
Option configures the WorkerPool
func WithMaxWorkers ¶
WithMaxWorkers sets the maximum number of workers
func WithMinWorkers ¶
WithMinWorkers sets the minimum number of workers
func WithPriorityPercentages ¶
WithPriorityPercentages sets worker allocation percentages
func WithTaskTimeout ¶
WithTaskTimeout sets the default task timeout
type PoolStats ¶
type PoolStats struct {
TotalWorkers int32
ActiveWorkers int32
HighPriority int32
MediumPriority int32
QueueLengths map[int]int
Throughput float64
AvgTaskTime time.Duration
RejectedTasks int32
TimeoutTasks int32
HungerEvents int32
}
PoolStats contains runtime statistics
type Task ¶
type Task struct {
Priority int // Task priority (High/Medium/Low)
Job func() error // The work function
SubmittedAt time.Time // When task was submitted
Timeout time.Duration // Timeout for this task
ResultChan chan<- TaskResult // Channel for results
}
Task represents a unit of work with priority
type TaskResult ¶
TaskResult contains task execution results
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool manages workers and task processing
func New ¶
func New(options ...Option) *WorkerPool
New creates a new WorkerPool with default configuration
func (*WorkerPool) Shutdown ¶
func (p *WorkerPool) Shutdown()
Shutdown gracefully shuts down the pool
func (*WorkerPool) Stats ¶
func (p *WorkerPool) Stats() PoolStats
Stats returns current pool statistics
func (*WorkerPool) Submit ¶
func (p *WorkerPool) Submit(task *Task) error
Submit adds a task to the work pool
func (*WorkerPool) SubmitWithContext ¶
func (p *WorkerPool) SubmitWithContext(ctx context.Context, task *Task) error
SubmitWithContext adds a task with context support
Click to show internal directories.
Click to hide internal directories.