pool

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 7 Imported by: 0

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

func WithLogger(l *logger.Logger) Option

WithLogger sets the logger for the pool to log panics if no PanicHandler is set.

func WithNonBlocking

func WithNonBlocking(b bool) Option

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

func WithQueueSize(size int) Option

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.

func New

func New(size int, opts ...Option) (Pool, error)

New creates a new fixed-size worker pool.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL