pool

package
v0.0.0-...-1c5d739 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

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

ErrItemUnavailable Error when an item cannot be allocated fromt the pool

Functions

This section is empty.

Types

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.

Jump to

Keyboard shortcuts

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