Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockingPool ¶
type BlockingPool[T any] interface { Pool[T] // GetContext waits to retrieve an object until ctx is cancelled or times out. GetContext(ctx context.Context) (T, bool) }
BlockingPool extends the Pool interface with context-aware blocking acquisition.
type ChanPool ¶
type ChanPool[T any] struct { // contains filtered or unexported fields }
ChanPool is a bounded object pool based on channels, suitable for scenarios requiring resource limits. Unlike SyncPool, ChanPool has an explicit capacity limit and objects are not subject to GC.
func NewChanPool ¶
NewChanPool creates a bounded object pool based on channels.
func (*ChanPool[T]) Close ¶
func (cp *ChanPool[T]) Close()
Close closes the pool and calls closeFn on all remaining objects. After calling Close, Get and GetContext will return zero values.
func (*ChanPool[T]) Get ¶
func (cp *ChanPool[T]) Get() T
Get retrieves an object from the pool without blocking.
func (*ChanPool[T]) GetContext ¶
GetContext waits to retrieve an object until ctx is cancelled or times out. If allowCreate is true and newFn is set, creates a new object when pool is empty. If allowCreate is false, always waits for an object from the pool.
type Option ¶
Option is a function that configures Options.
func WithAccept ¶
func WithAllowCreate ¶
type Options ¶
type Options[T any] struct { New func() T Reset func(T) T Accept func(T) bool Close func(T) AllowCreate bool // For ChanPool.GetContext: if true, create new object when pool is empty }
Options contains configuration functions for pool behavior.
type Pool ¶
type Pool[T any] interface { // Get retrieves an object from the pool. Get() T // Put attempts to return an object to the pool. Put(T) bool }
Pool defines the basic interface for a generic object pool.
type SyncPool ¶
type SyncPool[T any] struct { // contains filtered or unexported fields }
SyncPool is a generic object pool based on sync.Pool, suitable for frequent allocation of small objects.
func NewSyncPool ¶
NewSyncPool creates an object pool based on sync.Pool.