pool

package
v0.1.83 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 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 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

func New[T any]() *Pool[T]

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.

func (*Pool[T]) Put

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

Put adds x to the pool.

Jump to

Keyboard shortcuts

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