Documentation
¶
Index ¶
- type PoolOption
- type SizedPool
- func (sz *SizedPool[T]) Discard()
- func (sz *SizedPool[T]) Get(ctx context.Context) (T, error)
- func (sz *SizedPool[T]) GetN(ctx context.Context, n int64) ([]T, error)
- func (sz *SizedPool[T]) Put(x T)
- func (sz *SizedPool[T]) Size() int64
- func (sz *SizedPool[T]) Vary(ctx context.Context, x int64) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PoolOption ¶
PoolOption represents an option for configuring 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 ¶
Get retrieves an item from the pool, blocking if necessary until an item is available.
func (*SizedPool[T]) GetN ¶ added in v0.11.11
GetN retrieves n items from the pool, acquiring all n slots at once.
Use it instead of calling [Get] n times when the items are needed together: it never holds part of the slots while waiting for the rest, so concurrent callers cannot deadlock on each other.