Architecture
System overview of go-queue: public API, pending priority heap, worker pool, and lifecycle.
Overview
graph TB
App[Application] --> Enqueue[Enqueue]
App --> Start[Start]
App --> Shutdown[Shutdown]
Enqueue --> Pending[Pending Heap]
Start --> Workers[Worker Pool]
Pending --> Workers
Workers --> Execute[Execute / Timeout / Retry]
Shutdown --> Pending
Shutdown --> Workers
Data flow
- Caller creates a queue with
New, then Start spawns Workers goroutines.
Enqueue builds a task (preset priority, timeout, options) and pending.Push.
- A worker
Pops the highest-priority task (after promotion), then executes it under a timeout context.
- Success runs an optional async callback; failure may
setRetry and re-push at PriorityRetry.
Shutdown CAS-closes state, closes pending, and waits on the worker WaitGroup.
Module layout
Lifecycle states
stateDiagram-v2
[*] --> Created
Created --> Running: Start CAS
Running --> Closed: Shutdown CAS
Created --> Closed: Shutdown CAS
Closed --> Closed: Shutdown idempotent
Start only transitions Created → Running.
Shutdown may close from Created or Running; repeated calls are no-ops.
- When closed and the heap is empty, workers exit; on shutdown timeout the remaining length is reported.