conn_pool

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2020 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidConfig  = errors.New("invalid pool config")
	ErrPoolClosed     = errors.New("pool closed")
	ErrGetConnTimeout = errors.New("get conn timeout")
	ErrConnFactory    = errors.New("ConnFactory error")
)

Functions

This section is empty.

Types

type ConnFactory

type ConnFactory func() (io.Closer, error)

创建连接的方法

type ConnTestFunc added in v1.2.2

type ConnTestFunc func(closer io.Closer) bool

判断连接是否可用

type ErrorHandler

type ErrorHandler func(err error)

错误处理

type Option

type Option interface {
	// contains filtered or unexported methods
}

type OptionConnMaxAliveTime

type OptionConnMaxAliveTime time.Duration

连接最大存活时间

type OptionGetConnWaitDeadline

type OptionGetConnWaitDeadline time.Duration

获取连接最大等待时间

type OptionMaxOpen

type OptionMaxOpen int

池中最大资源数

type OptionMinOpen

type OptionMinOpen int

池中最少资源数

type Pool

type Pool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewPool

func NewPool(factory ConnFactory, errorHandler ErrorHandler, connTestFunc ConnTestFunc, options ...Option) (*Pool, error)

func (*Pool) Acquire

func (p *Pool) Acquire() (io.Closer, error)

func (*Pool) Close

func (p *Pool) Close() error

关闭连接池,释放所有资源

func (*Pool) CloseOne added in v1.3.2

func (p *Pool) CloseOne(closer io.Closer)

func (*Pool) Release

func (p *Pool) Release(closer io.Closer)

释放单个资源到连接池

Jump to

Keyboard shortcuts

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