freepool

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package freepool manages a free pool of objects that are expensive to create.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool is a small pool of recently returned objects with built-in cleanup.

func New

func New[T any](makeNew func() *T, clean func(v *T)) *Pool[T]

New returns a new free pool.

func NewStruct added in v0.13.0

func NewStruct[T any](cleanItem T) *Pool[T]

NewStruct returns a pool that produces provided clean structures.

func (*Pool[T]) Return

func (p *Pool[T]) Return(v *T)

Return returns an item to the pool after cleaning it.

func (*Pool[T]) Take

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

Take returns an item from the pool, and if not available makes a new one.

Jump to

Keyboard shortcuts

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