Skip to main content

Zero-dependency worker pool for Go

A bounded worker pool with retries, panic recovery, and graceful shutdown — plus typed futures, error groups, batching, a cron scheduler, and flow-control helpers. Standard library only.

go get github.com/KARTIKrocks/go-worker

Bounded Worker Pool

A fixed set of goroutines and a bounded queue, with blocking, non-blocking, and context-aware submits

Retries with Backoff

Exponential backoff, a delay cap, jitter, per-attempt timeouts, and permanent errors that skip retrying

Panic Recovery

A panicking job returns a PanicError with its stack trace; the worker keeps running

Graceful Shutdown

Drain the queue on Close, or force-cancel in-flight jobs after a timeout

Typed Futures

Submit a func returning (T, error) and await a typed result, with generics

Groups and Batches

Fan out with error collection or cancel-on-first-error, and process slices in chunks

Scheduler

Cron expressions, intervals, daily times, and one-shot tasks with overlap policies and jitter

Flow Control

Ticker, debouncer, throttler, and token-bucket rate limiter, all on top of the pool

Middleware and Hooks

Wrap every attempt for tracing or logging, and observe job and worker lifecycles

Metrics

Atomic counters for submitted, completed, failed, retried, and panicked jobs, plus throughput

Pause and Resume

Stop picking up new work without shutting down, then carry on where you left off

Zero Dependencies

Standard library only — nothing to audit, nothing to update

Why go-worker?

A go statement and a sync.WaitGroup get you concurrency. Running background work safely in production — bounded, retried, cancellable, observable, and shut down cleanly — is the part go-worker provides.

Capabilitygo-workerGoroutines + WaitGroup
Bounded concurrency and backpressureIncludedYou build it
Retries with backoff, jitter, and permanent errorsIncludedYou build it
Panic recovery with stack tracesIncludedYou build it
Per-attempt timeouts and cancellationIncludedYou build it
Graceful drain and forced shutdownIncludedYou build it
Cron, interval, and one-shot schedulingIncludedYou build it
Debounce, throttle, and rate limitingIncludedYou build it
Metrics and lifecycle hooksIncludedYou build it

Performance

Measured on an Intel i5-11400H (12 cores), Go 1.27, Linux, with an 8-worker pool and 12 goroutines submitting no-op jobs concurrently — so these figures are the pool's own overhead, not your jobs'.

Submit

0.9 µs/op

5 allocs, sustained with a full queue

SubmitWait

1.5 µs/op

8 allocs, including the result handoff

Throughput

~1.1M jobs/s

no-op jobs, 8 workers

Dependencies

0

standard library only

Reproduce them yourself with go test -bench=. -benchmem ./... in the repository root. The benchmark table in the README lists every figure measured.