fixedpool

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FixedPool

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

A FixedPool like sync.Pool. But it's limited capacity. When pool is full, Put will abandon and call destroyFunc to destroy the object.

func New

func New(name string, newFunc func() (any, error), destroyFunc func(any), capacity int) *FixedPool

New return a FixedPool

func (*FixedPool) Get

func (p *FixedPool) Get() (any, error)

Get selects an arbitrary item from the pool, removes it from the pool, and returns it to the caller. Get may choose to ignore the pool and treat it as empty. Callers should not assume any relation between values passed to Put and the values returned by Get.

If pool is empty, Get returns the result of calling newFunc.

func (*FixedPool) Put

func (p *FixedPool) Put(x any)

Put adds x to the pool. If pool is full, x will be abandoned, and it's destroy function will be called.

Jump to

Keyboard shortcuts

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