pool

package
v0.0.0-...-4973d3c Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: AGPL-3.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Poolobj

type Poolobj[T any] struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool[T any](maxsize int, initcreate int, constructor func(*T), destructor func(*T)) Poolobj[T]

NewPool creates a new Poolobj initialized with the given parameters.

maxsize specifies the maximum number of objects that can be kept in the pool.

initcreate specifies the initial number of objects to create in the pool on startup.

constructor, if non-nil, is called whenever a new object needs to be created.

destructor, if non-nil, is called whenever an object is removed from the pool.

func (*Poolobj[T]) Get

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

Get retrieves an object from the pool or creates a new one if none are available. If a constructor was provided, it will be called to initialize any newly created objects.

func (*Poolobj[T]) Put

func (p *Poolobj[T]) Put(bo *T)

Put returns an object to the pool. If the pool is not at capacity, it calls the destructor function if provided, then sends the object back on the channel.

Jump to

Keyboard shortcuts

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