pool

package
v0.0.0-...-3b1ec4e Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnItem

type ConnItem struct {
	net.Conn
	// contains filtered or unexported fields
}

instance in conn pool

func (*ConnItem) Close

func (r *ConnItem) Close() error

func (*ConnItem) Read

func (r *ConnItem) Read(buf []byte) (int, error)

func (*ConnItem) Write

func (r *ConnItem) Write(data []byte) (int, error)

type ConnPool

type ConnPool struct {
	MinIdle   int
	MaxIdle   int
	MaxActive int
	Wait      bool

	IdleTimeout     time.Duration
	MaxConnLifetime time.Duration
	// contains filtered or unexported fields
}

func (*ConnPool) CheckAlive

func (r *ConnPool) CheckAlive(ci *ConnItem) bool

CheckAlive default checkfunc to test whether a connection is alive or not

func (*ConnPool) Close

func (r *ConnPool) Close() error

close the pool

func (*ConnPool) Get

func (r *ConnPool) Get(ctx context.Context) (ci *ConnItem, err error)

get a conn from pool

func (*ConnPool) Prepare

func (r *ConnPool) Prepare(ctx context.Context)

Prepare prepare MinIdle number of connections in advance so can reduce the propability of creating connections when launch IO actions.

func (*ConnPool) RegisterCheckFunc

func (r *ConnPool) RegisterCheckFunc(interval time.Duration, checkFunc func(*ConnItem) bool)

RegisterCheckFunc register function to check whether a connection is alive

type Option

type Option func(*Options)

func WithDialTimeout

func WithDialTimeout(t time.Duration) Option

func WithIdleTimeout

func WithIdleTimeout(t time.Duration) Option

func WithMaxActive

func WithMaxActive(s int) Option

func WithMaxConnLifetime

func WithMaxConnLifetime(t time.Duration) Option

func WithMaxIdle

func WithMaxIdle(m int) Option

func WithMinIdle

func WithMinIdle(n int) Option

some helper funcs

func WithWait

func WithWait(w bool) Option

type Options

type Options struct {
	MinIdle int
	// -1 represent no limit
	MaxIdle int
	// -1 represent no limit
	MaxActive int
	// whether wait if reach max conn
	Wait bool
	// idle conn timeout time
	IdleTimeout     time.Duration
	MaxConnLifetime time.Duration
	DialTimeout     time.Duration
}

type PoolFactory

type PoolFactory interface {
	Get(ctx context.Context, network, addr string) (net.Conn, error)
}

func NewConnPoolFactory

func NewConnPoolFactory(opt ...Option) PoolFactory

create a new poolfactory manager

Jump to

Keyboard shortcuts

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