Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool[T any] struct { // New optionally specifies a function to generate // a value when Get would otherwise return nil. // It may not be changed concurrently with calls to Get. New func() *T // contains filtered or unexported fields }
Pool is a type-safe wrapper around sync.Pool that provides a generic, concurrency-safe object pool for any type T.
func New ¶
New creates a new Pool that allocates new zero-valued objects of type T when none are available.
func (*Pool[T]) Get ¶
func (p *Pool[T]) Get() *T
Get selects an arbitrary item from the Pool, removes it from the Pool, and returns it to the caller. Get may choose to ignore the pool and treat it as empty. Callers should not assume any relation between values passed to Pool.Put and the values returned by Get.
If Get would otherwise return nil and p.New is non-nil, Get returns the result of calling p.New.
Click to show internal directories.
Click to hide internal directories.