Version: v0.0.0-...-45f56e5 Latest Latest

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

Go to latest
Published: Jun 4, 2021 License: Apache-2.0 Imports: 7 Imported by: 0




This section is empty.


View Source
var ErrItemUnavailable = errors.New("Pool Item not avaialable")

ErrItemUnavailable Error when an item cannot be allocated fromt the pool


This section is empty.


type Item

type Item struct {
	Item interface{}
	// contains filtered or unexported fields

Item wrapper type for items stored in pool

type ItemFactory

type ItemFactory func() (interface{}, error)

ItemFactory function to create an item for the pool

type Pool

type Pool interface {
	// Borrow item from pool, returns ErrItemUnavailable if none available
	Borrow() (*Item, error)

	// Borrow item from pool, wait timeout. If timeout < 0 wait indefinitely. Returns ErrItemUnavailable if object not available
	BorrowWait(timeout time.Duration) (*Item, error)

	// Return item back to pool
	Return(item *Item) error

	// Remove removes the object from the pool
	Remove(item *Item) error

	//Returns the current number of items borrowed
	Borrowed() int

	//Returns the current number of items in the pool (not borrowed)
	Idle() int

Pool interface for pooling arbitrary objects

func NewPool

func NewPool(capacity int, itemFactory ItemFactory) (Pool, error)

NewPool create a pool with a capacity and factory for creating items.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL