pool

package
v0.0.0-...-7bde1eb Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2016 License: MIT Imports: 3 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("Pool is closed")

ErrClosed indicates this pool is already closed.

Functions

This section is empty.

Types

type Closer

type Closer interface {
	Close() error
}

Closer interface implements Close().

type Pool

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

Pool is a pool of resources with a given allocator. If the a resource implements Closer, then it Close() will be called when resource is removed from the pool.

func New

func New(name string, min, max int, alloc func() (interface{}, error)) (*Pool, error)

New returns a new, initialized Pool.

func (*Pool) Allocated

func (p *Pool) Allocated() int

Allocated returns current count of resources being managed by the pool.

func (*Pool) Close

func (p *Pool) Close() (err error)

Close removes all resources from the pool.

func (*Pool) Get

func (p *Pool) Get() (interface{}, error)

Get returns a resource or err if pool is closed. This function will block until a resource is available.

func (*Pool) Put

func (p *Pool) Put(res interface{})

Put places a resource back into the Pool.

Jump to

Keyboard shortcuts

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