pool

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory[T any] func(context.Context) (T, error)

type Option

type Option[T any] func(*pool[T])

func WithAge

func WithAge[T any](maxAge int64) Option[T]

WithAge defined element max age (millisecond)

func WithEvict

func WithEvict[T any](cb func(T)) Option[T]

WithEvict set the evict callback

func WithSize

func WithSize[T any](maxSize int) Option[T]

WithSize defined max size of Pool

type Pool

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

Pool is for GC, see New for detail

func New

func New[T any](factory Factory[T], options ...Option[T]) *Pool[T]

func (Pool) Get

func (p Pool) Get() (T, error)

func (Pool) GetContext

func (p Pool) GetContext(ctx context.Context) (T, error)

func (Pool) Put

func (p Pool) Put(item T)

Jump to

Keyboard shortcuts

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