types

package
v0.0.0-...-eec02a6 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package types provides shared types for the workerpool package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config interface {
	// PoolConfig is a marker method to ensure only valid configs are used.
	PoolConfig()
	// Copy returns a deep copy of this configuration.
	Copy() Config
}

Config is an interface that all pool configurations must implement. Each pool implementation defines its own config type.

type MultiPool

type MultiPool interface {
	Pool

	// RunningByIndex returns the number of currently executing workers in a specific pool.
	// Returns an error if the index is out of bounds.
	RunningByIndex(idx int) (int, error)

	// FreeByIndex returns the number of available workers in a specific pool.
	// Returns an error if the index is out of bounds.
	FreeByIndex(idx int) (int, error)

	// WaitingByIndex returns the number of tasks waiting in a specific pool.
	// Returns an error if the index is out of bounds.
	WaitingByIndex(idx int) (int, error)
}

MultiPool defines the base interface for a multipool. Implementations must be safe for concurrent use. This is for multi-pool implementations that consist of multiple underlying pools with load balancing.

type Pool

type Pool interface {
	// Start initializes and starts the worker pool.
	// Must be called before submitting tasks.
	Start(ctx context.Context) error

	// Submit submits a task to the pool for execution.
	// Returns an error if the pool is closed or the task cannot be submitted.
	Submit(ctx context.Context, task func()) error

	// Shutdown gracefully shuts down the pool.
	// It stops accepting new tasks and waits indefinitely for running tasks to complete.
	// For time-bounded shutdown, use ShutdownWithTimeout instead.
	Shutdown(ctx context.Context) error

	// ShutdownWithTimeout gracefully shuts down the pool with a timeout.
	// It stops accepting new tasks and waits for running tasks to complete.
	// Returns an error if the timeout expires before shutdown completes.
	ShutdownWithTimeout(timeout time.Duration) error

	// IsStarted returns true if the pool has been started.
	IsStarted() bool

	// IsClosed returns true if the pool has been shut down.
	IsClosed() bool

	// Running returns the number of currently executing workers.
	Running() int

	// Cap returns the capacity (maximum number of workers) of the pool.
	Cap() int

	// Free returns the number of available (idle) workers.
	// Returns -1 if the pool is closed or doesn't support this metric.
	Free() int

	// Waiting returns the number of tasks waiting in the queue.
	Waiting() int

	// Stats returns all pool statistics at once.
	Stats() PoolStats
}

Pool defines the base interface for a worker pool. Implementations must be safe for concurrent use.

type PoolStats

type PoolStats struct {
	Capacity int // Maximum number of workers
	Running  int // Number of currently executing workers
	Free     int // Number of available (idle) workers
	Waiting  int // Number of tasks waiting in the queue
}

PoolStats contains runtime statistics for a worker pool.

Jump to

Keyboard shortcuts

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