sizedpool

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 4 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PoolOption

type PoolOption[T any] func(*SizedPool[T]) error

PoolOption represents an option for configuring the SizedPool.

func WithPool

func WithPool[T any](p *sync.Pool) PoolOption[T]

WithPool sets the underlying sync.Pool for the SizedPool.

func WithSize

func WithSize[T any](size int64) PoolOption[T]

WithSize sets the maximum size of the SizedPool.

type SizedPool

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

SizedPool is a pool with a maximum size that blocks on Get when the pool is exhausted.

func New

func New[T any](options ...PoolOption[T]) (*SizedPool[T], error)

New creates a new SizedPool with the given options.

func (*SizedPool[T]) Discard added in v0.8.0

func (sz *SizedPool[T]) Discard()

Discard releases the semaphore slot without returning the item to the pool.

Use this when you need to discard an item obtained via [Get] without reusing it. This prevents semaphore leaks when items are intentionally not returned to the pool.

func (*SizedPool[T]) Get

func (sz *SizedPool[T]) Get(ctx context.Context) (T, error)

Get retrieves an item from the pool, blocking if necessary until an item is available.

func (*SizedPool[T]) Put

func (sz *SizedPool[T]) Put(x T)

Put returns an item to the pool and releases the semaphore slot.

func (*SizedPool[T]) Size

func (sz *SizedPool[T]) Size() int64

Current size of the pool

func (*SizedPool[T]) Vary

func (sz *SizedPool[T]) Vary(ctx context.Context, x int64) error

Vary capacity by x - it's internally enqueued as a normal Acquire/Release operation as other Get/Put but tokens are held internally

Jump to

Keyboard shortcuts

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