pool

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNewFunc     = errors.New("new func is nil")
	ErrClosed      = errors.New("pool is closed")
	ErrGetTimeout  = errors.New("get connection timeout")
	ErrOverMaxSize = errors.New("over pool max size")
	ErrIDConflict  = errors.New("conn id conflict")
)

Functions

func NewPool

func NewPool(newFunc func(ctx context.Context) (Conn, error), opts ...Option) (*connPool, error)

Types

type Conn

type Conn interface {
	GetID() string
	Close(ctx context.Context) error
}

type Option

type Option func(*Options)

func WithBreakerThreshold

func WithBreakerThreshold(s uint32) Option

func WithGetConnTimeout

func WithGetConnTimeout(t time.Duration) Option

func WithGetQuickFail

func WithGetQuickFail() Option

func WithIdleSize

func WithIdleSize(s uint32) Option

func WithPoolSize

func WithPoolSize(s uint32) Option

type Options

type Options struct {
	PoolSize         uint32
	IdleSize         uint32
	BreakerThreshold uint32 // 连接失败熔断阈值
	GetQuickFail     bool
	GetConnTimeout   time.Duration
}

type Pool

type Pool interface {
	Get() (Conn, error)
	Put(ctx context.Context, conn Conn) error
	Remove(ctx context.Context, conn Conn) error
	Close(ctx context.Context) error
	Stats() Stats
}

type Stats

type Stats struct {
	Hits            uint64
	Misses          uint64
	Removes         uint64
	IDConflicts     uint64
	ErrOverMaxSizes uint64
	Timeouts        uint64
	Breakers        uint64
	ConnCount       uint32
	IdleCount       uint32
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳