objpool

package
v1.12.3 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetPassDBResultPoolNewFunc

func SetPassDBResultPoolNewFunc(newFunc func() interface{})

SetPassDBResultPoolNewFunc sets the new function for the global PassDBResultPool instance This function must be called before GetPassDBResultPool is called for the first time It is typically called during application initialization

Types

type PassDBResultPool

type PassDBResultPool struct {
	// contains filtered or unexported fields
}

PassDBResultPool is a pool for objects implementing the PassDBResultPoolable interface It provides methods to get and put these objects

func GetPassDBResultPool

func GetPassDBResultPool() *PassDBResultPool

GetPassDBResultPool returns the global PassDBResultPool instance It panics if SetPassDBResultPoolNewFunc has not been called before

func NewPassDBResultPool

func NewPassDBResultPool(newFunc func() any) *PassDBResultPool

NewPassDBResultPool creates a new PassDBResultPool with the given new function The new function is called when the pool is empty and a new object is needed

func (*PassDBResultPool) Get

func (p *PassDBResultPool) Get() any

Get retrieves an object from the pool If the pool is empty, a new object is created using the new function

func (*PassDBResultPool) Put

func (p *PassDBResultPool) Put(obj any)

Put returns an object to the pool The object is reset before being returned to the pool

type PassDBResultPoolable

type PassDBResultPoolable interface {
	Resettable
	IsPassDBResult() bool
}

PassDBResultPoolable is an interface for objects that can be pooled in the PassDBResultPool Objects implementing this interface can be put in the PassDBResultPool

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool is a generic object pool that manages reusable objects It provides methods to get objects from the pool and put them back

func NewPool

func NewPool(newFunc func() any) *Pool

NewPool creates a new Pool with the given new function The new function is called when the pool is empty and a new object is needed

func (*Pool) Get

func (p *Pool) Get() any

Get retrieves an object from the pool If the pool is empty, a new object is created using the new function

func (*Pool) Put

func (p *Pool) Put(obj any)

Put returns an object to the pool If the object implements the Resettable interface, it is reset before being returned to the pool

type Resettable

type Resettable interface {
	// Reset resets all fields of the object to their zero values
	Reset()
}

Resettable is an interface for objects that can be reset Objects implementing this interface can be reset to their zero values This is useful for objects that are stored in a sync.Pool

Jump to

Keyboard shortcuts

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