kratos: github.com/bilibili/kratos/pkg/container/pool Index | Files

package pool

import "github.com/bilibili/kratos/pkg/container/pool"

Index

Package Files

list.go pool.go slice.go

Variables

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

type Config Uses

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 Uses

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 Uses

func NewList(c *Config) *List

NewList creates a new pool.

func (*List) Close Uses

func (p *List) Close() error

Close releases the resources used by the pool.

func (*List) Get Uses

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 Uses

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

Put put item into pool.

func (*List) Reload Uses

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

Reload reload config.

type Pool Uses

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 Uses

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 Uses

func NewSlice(c *Config) *Slice

NewSlice creates a new pool.

func (*Slice) Close Uses

func (p *Slice) Close() error

Close close pool.

func (*Slice) Get Uses

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

Get returns a newly-opened or cached *item.

func (*Slice) Put Uses

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 Uses

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

Reload reload config.

Package pool imports 7 packages (graph) and is imported by 2 packages. Updated 2019-06-11. Refresh now. Tools for package owners.