pool

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 3 Imported by: 1

README

GoDoc Build Status Coverage Status Report Card

Documentation

Overview

Package pool provides types and functionality related to object pooling.

Index

Constants

View Source
const Version = "v0.1.1"

Version is the current version of the library.

Variables

View Source
var ErrCorruptPool = errors.New("corrupt pool")

ErrCorruptPool is returned by Pool.Get when the de-pooled object's type is unconvertible to the pool's intended object type.

Functions

This section is empty.

Types

type Constructor

type Constructor[T any] func() T

A Constructor creates a new object of type T.

type Pool

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

Pool is a strongly-typed object pool.

func New

func New[T any](ctor Constructor[T]) *Pool[T]

New creates a new Pool compatible with objects of type T with the given Constructor for T.

func NewWithReleaser

func NewWithReleaser[T any](ctor Constructor[T], release Releaser[T]) *Pool[T]

NewWithReleaser creates a new Pool compatible with objects of type T with the given Constructor and Releaser for T.

func (*Pool[T]) Get

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

Get de-pools or creates an object of type T.

func (*Pool[T]) Put

func (p *Pool[T]) Put(x T)

Put places the given object back into the pool. If a Releaser is configured, it will be called prior to pooling the object.

type Releaser

type Releaser[T any] func(T)

A Releaser resets an object of type T for reuse.

Jump to

Keyboard shortcuts

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