Documentation
¶
Overview ¶
Package pool is a thin wrapper around github.com/alitto/pond/v2 that gives hex applications a worker pool primitive for bounded in-process concurrency.
Use hex/pool when you need to fan out N tasks across a bounded number of goroutines. It is orthogonal to hex/queue (delivery + durability) and hex/cron (timing): a queue consumer, cron job, or HTTP handler can all use a pool to run their work concurrently.
See ADR-0010 for the wrap-vs-roll-own decision.
Example:
p := pool.New(10) // 10-worker pool
defer p.Shutdown(ctx) // waits for in-flight
for _, item := range items {
item := item
p.Submit(func() { process(item) })
}
// Or with results:
rp := pool.NewResult[User](10)
task := rp.SubmitErr(func() (User, error) {
return svc.Get(ctx, id)
})
user, err := task.Wait()
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BasePool ¶
type BasePool interface {
StopAndWait()
Stop() pond.Task
RunningWorkers() int64
SubmittedTasks() uint64
WaitingTasks() uint64
SuccessfulTasks() uint64
FailedTasks() uint64
CompletedTasks() uint64
DroppedTasks() uint64
CanceledTasks() uint64
MaxConcurrency() int
QueueSize() int
Stopped() bool
}
BasePool is the minimum interface every pond pool satisfies. Used by Shutdown and Snapshot so the same helpers work for Pool and ResultPool.
type Metrics ¶
type Metrics struct {
Timestamp time.Time
MaxConcurrency int
QueueSize int
RunningWorkers int64
SubmittedTasks uint64
WaitingTasks uint64
SuccessfulTasks uint64
FailedTasks uint64
CompletedTasks uint64
DroppedTasks uint64
CanceledTasks uint64
Stopped bool
}
Metrics is a point-in-time snapshot of a pool's counters. Read via Snapshot for consumers that want to expose pool health via /healthz-adjacent endpoints or metrics scrapers.
type Option ¶
Option configures a new pool. Aliased from pond so callers can pass upstream options directly if they need something the hex helpers do not surface.
func WithContext ¶
WithContext sets a base context on the pool. When ctx is cancelled the pool stops accepting new tasks and returns ErrPoolStopped.
func WithNonBlocking ¶
WithNonBlocking makes Submit drop tasks that cannot be queued instead of blocking. Combine with WithQueueSize.
func WithQueueSize ¶
WithQueueSize caps the number of pending tasks the pool will accept before blocking (or dropping, with WithNonBlocking).
type Pool ¶
Pool is the type alias for pond's non-generic pool. Consumers get the full pond API through the alias.
type ResultPool ¶
type ResultPool[R any] = pond.ResultPool[R]
ResultPool is the type alias for pond's typed result pool.
type ResultTask ¶
ResultTask represents a submitted task that returns a typed result.