pool

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2020 License: MIT Imports: 7 Imported by: 0

README

pool

项目简介

通用连接池实现

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPoolExhausted connections are exhausted.
	ErrPoolExhausted = errors.New("container/pool exhausted")
	// ErrPoolClosed connection pool is closed.
	ErrPoolClosed = errors.New("container/pool closed")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Active number of items allocated by the pool at a given time.
	// When zero, there is no limit on the number of items in the pool.
	Active int
	// Idle number of idle items in the pool.
	Idle int
	// Close items after remaining item for this duration. If the value
	// is zero, then item items are not closed. Applications should set
	// the timeout to a value less than the server's timeout.
	IdleTimeout xtime.Duration
	// If WaitTimeout is set and the pool is at the Active limit, then Get() waits WatiTimeout
	// until a item to be returned to the pool before returning.
	WaitTimeout xtime.Duration
	// If WaitTimeout is not set, then Wait effects.
	// if Wait is set true, then wait until ctx timeout, or default flase and return directly.
	Wait bool
}

Config is the pool configuration struct.

type List

type List struct {
	// New is an application supplied function for creating and configuring a
	// item.
	//
	// The item returned from new must not be in a special state
	// (subscribed to pubsub channel, transaction started, ...).
	New func(ctx context.Context) (io.Closer, error)
	// contains filtered or unexported fields
}

List .

func NewList

func NewList(c *Config) *List

NewList creates a new pool.

func (*List) Close

func (p *List) Close() error

Close releases the resources used by the pool.

func (*List) Get

func (p *List) Get(ctx context.Context) (io.Closer, error)

Get returns a item from the idles List or get a new item.

func (*List) Put

func (p *List) Put(ctx context.Context, c io.Closer, forceClose bool) error

Put put item into pool.

func (*List) Reload

func (p *List) Reload(c *Config) error

Reload reload config.

type Pool

type Pool interface {
	Get(ctx context.Context) (io.Closer, error)
	Put(ctx context.Context, c io.Closer, forceClose bool) error
	Close() error
}

Pool interface.

type Slice

type Slice struct {
	// New is an application supplied function for creating and configuring a
	// item.
	//
	// The item returned from new must not be in a special state
	// (subscribed to pubsub channel, transaction started, ...).
	New func(ctx context.Context) (io.Closer, error)
	// contains filtered or unexported fields
}

Slice .

func NewSlice

func NewSlice(c *Config) *Slice

NewSlice creates a new pool.

func (*Slice) Close

func (p *Slice) Close() error

Close close pool.

func (*Slice) Get

func (p *Slice) Get(ctx context.Context) (io.Closer, error)

Get returns a newly-opened or cached *item.

func (*Slice) Put

func (p *Slice) Put(ctx context.Context, c io.Closer, forceClose bool) error

Put adds a item to the p's free pool. err is optionally the last error that occurred on this item.

func (*Slice) Reload

func (p *Slice) Reload(c *Config) error

Reload reload config.

Jump to

Keyboard shortcuts

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