workerpool

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: 5 Imported by: 0

Documentation

Overview

Package workerpool provides interfaces and utilities for managing goroutine pools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustNew

func MustNew[T types.Pool](ctx context.Context, cfgs ...types.Config) T

MustNew is like New but panics if pool creation fails.

func New

func New[T types.Pool](ctx context.Context, cfgs ...types.Config) (T, error)

New creates a new Pool using the provided implementation-specific config file. The generic type parameter T specifies which interface the caller needs:

  • Pool: basic pool operations only
  • PoolWithStats: pool operations plus statistics (Running, Cap, Waiting, Stats)
  • MultiPoolWithStats: multi-pool operations plus per-pool statistics

If no config is provided, a default config is chosen based on the requested interface T. Currently, ants is the default implementation which supports all pool types. If the requested pool type doesn't support the required interface, an error is returned.

Example usage:

	// Default single pool
	pool, err := workerpool.New[workerpool.Pool](ctx)

 // Default single poolWithStats
 pool, err := workerpool.New[workerpool.PoolWithStats](ctx)

 // Default multipool
 pool, err := workerpool.New[workerpool.MultiPool](ctx)

 // Default multipool multipoolWithStats
 pool, err := workerpool.New[workerpool.MultipoolWithStats](ctx)

	// Basic pool with ants config
	pool, err := workerpool.New[workerpool.Pool](ctx, ants.Config{NumWorkers: 10})

	// Pool with stats
	poolWithStats, err := workerpool.New[workerpool.PoolWithStats](ctx, ants.Config{
	    NumWorkers:  10,
	    PreAlloc:    true,
	    NonBlocking: false,
	})

	// Multi-pool with stats
	multiPool, err := workerpool.New[workerpool.MultiPoolWithStats](ctx, ants.MultiPoolConfig{
	    NumPools:              4,
	    NumWorkersPerPool:     10,
	    LoadBalancingStrategy: ants.RoundRobin,
	})

Types

This section is empty.

Directories

Path Synopsis
Package types provides shared types for the workerpool package.
Package types provides shared types for the workerpool package.

Jump to

Keyboard shortcuts

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