pooling

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option[T any] func(*Pool[T])

Option configures a Pool.

func WithFinalizer

func WithFinalizer[T any](fn func(T)) Option[T]

WithFinalizer sets a cleanup function called before items are returned.

func WithMaxSize

func WithMaxSize[T any](n int) Option[T]

WithMaxSize limits the pool to n active items.

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

Pool is a generic object pool with optional max size and finalizer.

func New

func New[T any](factory func() T, opts ...Option[T]) *Pool[T]

New creates a new Pool using factory to create items.

func (*Pool[T]) Get

func (p *Pool[T]) Get() T

func (*Pool[T]) Put

func (p *Pool[T]) Put(item T)

Jump to

Keyboard shortcuts

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