pool

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosedPool     = fmt.Errorf("pool is closed")
	ErrNewFuncNil     = fmt.Errorf("newFunc for pool is nil, can not create connection")
	ErrAcquireTimeout = fmt.Errorf("timeout for Acquire from the pool. Need to increase the maxCap for pool")
)

Functions

This section is empty.

Types

type ConnPool

type ConnPool interface {
	Get() (any, error)
	Pop() (any, bool)
	Put(v any)
	Destroy()
	Len() int
	Close(v any)
}

type Pool

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

Pool common connection pool

func New

func New(ctx context.Context, maxCap int32, acquireSemaTimeout time.Duration, newFunc func() (any, error), closeFunc func(any)) *Pool

New create a pool with capacity

func (*Pool) Close

func (p *Pool) Close(v any)

Close is closed a connection

func (*Pool) Destroy

func (p *Pool) Destroy()

Destroy close all connections and deactivate the pool

func (*Pool) Get

func (p *Pool) Get() (any, error)

Get returns a conn from store or create one

func (*Pool) Len

func (p *Pool) Len() int

Len returns current connections in pool

func (*Pool) Pop

func (p *Pool) Pop() (any, bool)

Pop return available conn without block

func (*Pool) Put

func (p *Pool) Put(v any)

Put set back conn into store again

Jump to

Keyboard shortcuts

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