pool

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config[PT item[T], T any] struct {
	// CreateFunc is used to create pool item.
	// Timeout is not set as context.WithTimeout
	// because this is running context for long-lived item.
	// Timeout itself should limit only creation steps,
	// and it is responsibility of CreateFunc to handle it appropriately.
	CreateFunc func(ctx context.Context, createTimeout time.Duration) (PT, error)

	Logger logger.Logger

	// CreateTimeout limits runtime for CreateFunc.
	// This timeout cannot be less than a second (minCreateTimeout).
	// Default is 3 seconds (defaultCreateTimeout).
	CreateTimeout time.Duration

	// Lifetime specifies item lifetime after which it will be closed
	// and new item will be created instead.
	// 0 lifetime means item has infinite lifetime and item recycling
	// is not running.
	// Lifetime cannot be less than 5 seconds (minItemLifetime).
	Lifetime time.Duration

	// RecycleWindow specifies time interval for item recycling:
	// [Lifetime-RecycleWindow;Lifetime+RecycleWindow]
	// This prevents service degradation caused by recycling of
	// significant number of items created at the same time.
	RecycleWindow time.Duration

	// PoolSize specifies amount of items in pool.
	PoolSize uint

	// Ready thresholds specifies transition points (in percents) for ready status.
	// If amount of inUse + idle sessions is greater or equal than
	// high threshold then pool is Ready.
	// If this amount is equal or less than low threshold then pool is NotReady.
	// Thresholds should be in range [0;100] and satisfy lo < hi condition
	// (must not be equal!). If these conditions are not met, pool will fall back
	// to default lo=0, hi=50 values.
	ReadyThresholdPercentHigh uint
	ReadyThresholdPercentLow  uint
	// contains filtered or unexported fields
}

Config holds pool configuration.

type Pool

type Pool[PT item[T], T any] struct {
	// contains filtered or unexported fields
}

func New

func New[PT item[T], T any](ctx context.Context, cfg Config[PT, T]) *Pool[PT, T]

func (*Pool[PT, T]) Close

func (p *Pool[PT, T]) Close() error

func (*Pool[PT, T]) Get

func (p *Pool[PT, T]) Get(rCtx context.Context) PT

func (*Pool[PT, T]) Put

func (p *Pool[PT, T]) Put(itm PT)

func (*Pool[PT, T]) Ready added in v0.0.2

func (p *Pool[PT, T]) Ready() bool

Jump to

Keyboard shortcuts

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