Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrPoolClosed is returned when submitting to a closed pool. ErrPoolClosed = errors.New("pool closed") // ErrPoolFull is returned when the pool queue is full in non-blocking mode. ErrPoolFull = errors.New("pool full") )
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*options)
Option defines a functional option for the Pool.
func WithLogger ¶
WithLogger sets the logger for the pool to log panics if no PanicHandler is set.
func WithNonBlocking ¶
WithNonBlocking makes Submit return immediately with ErrPoolFull if the pool (queue) is full. Default is false (blocking).
func WithPanicHandler ¶
func WithPanicHandler(h func(interface{})) Option
WithPanicHandler sets a callback for when a worker panics. If set, this handler is called with the recover() result.
func WithQueueSize ¶
WithQueueSize sets the size of the task queue (buffered channel). If 0 or negative, it defaults to the pool size.
type Pool ¶
type Pool interface {
// Submit submits a task to the pool.
Submit(task func()) error
// Release closes the pool and waits for workers to finish.
Release()
// Running returns the number of currently running workers (processing tasks).
Running() int
// Cap returns the capacity (number of workers) of the pool.
Cap() int
}
Pool interface defines the worker pool behaviors.
Click to show internal directories.
Click to hide internal directories.