generic_syncpool

package
v0.0.0-...-eec02a6 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 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 {
	sync.Pool
}

Pool is a generic wrapper around sync.Pool that provides type-safe Get and Put methods. This eliminates the need for type assertions in the calling code and allows the compiler to optimize better since exact types are known at compile time.

Example usage:

type MyData struct { /* ... */ }
pool := utils.NewPool(func() *MyData { return &MyData{} })
data := pool.Get()  // Returns *MyData, no type assertion needed
// ... use data ...
pool.Put(data)

func NewPool

func NewPool[T any](newF func() T) *Pool[T]

NewPool creates a new generic Pool with the given constructor function. The constructor is called when the pool is empty and needs to create a new value.

func (*Pool[T]) Get

func (p *Pool[T]) Get() T

Get retrieves a value from the pool and returns it with the correct type. The type assertion is hidden inside this method, keeping calling code clean.

func (*Pool[T]) Put

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

Put adds a value back to the pool for reuse.

Jump to

Keyboard shortcuts

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