v1.0.0 — Stable Release
go-workerpool v1.0.0
First stable release of go-workerpool — a lightweight Go worker pool with non-blocking job submission, caller-controlled timeouts, and graceful shutdown.
Features
- Configurable workers and queue — NumWorkers(n) and JobQueueSize(n)
- Caller-controlled timeout — Submit(ctx, job) respects context deadlines
- Graceful shutdown — Stop() drains all queued jobs with a live context before canceling
- Lock-free close detection — uses atomic + recover (no mutex on hot path)
- Error callback — OnError(fn) for observing failed jobs
- Metrics hook — WithMetrics(m) interface for observability (processed/failed counts)
- Queue monitoring — Len() returns current queue depth
- Pluggable handler — implement Handler interface for custom job processing
- Pluggable logger — WithLogger(l) or use default log.Printf
- Idempotent Stop — safe to call multiple times
API
go
wp := workerpool.NewWorkerPool(
workerpool.NumWorkers(4),
workerpool.JobQueueSize(10),
workerpool.SetHandler(&MyHandler{}),
workerpool.OnError(func(job workerpool.Job, err error) { /* ... */ }),
)
wp.Start()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
wp.Submit(ctx, workerpool.Job{ID: "task-1", Data: payload})
wp.Stop()
Examples
- Basic usage — _example/main.go
- Kafka consumer group with DLQ — _example/kafka/main.go
Requirements
- Go 1.22+
- Zero external dependencies