pool

package module
v0.0.0-...-62e4a6e Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: BSD-3-Clause Imports: 0 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 struct {
	// contains filtered or unexported fields
}

A Pool is a set of objects that may be individually saved and retrieved.

Unlike Go's sync.Pool these objects are persistent and are not subject to be collected by the GC.

A Pool is safe for use by multiple goroutines simultaneously.

func New

func New(size int, new func() any, reset func(any)) *Pool

New creates a new Pool. Size sets the maximum number of objects the Pool can hold. If 'new' is set, 'new' will be called to allocate a new object when Get() is called on an empty Pool. If 'reset' is set, 'reset' will be called on the object returned by Get() if it was previously Put() in the Pool.

func (*Pool) Get

func (p *Pool) Get() any

Get selects an arbitrary object from the Pool, removes it from the Pool, and returns it to the caller. Callers should not assume any relation between values passed to Put and the values returned by Get.

func (*Pool) Put

func (p *Pool) Put(x any)

Put adds x to the pool. If the pool is already at maximum capacity, the object will be dropped.

Jump to

Keyboard shortcuts

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