pool

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: Apache-2.0 Imports: 7 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 {
	Logger logger.Logger

	// 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)

	// 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 greater than 0 and less than 5 seconds (minItemLifetime).
	Lifetime time.Duration

	// RecycleWindow specifies time interval for item recycling:
	// [Lifetime-RecycleWindow;Lifetime+RecycleWindow]
	// This prevents items to all be recycled in the same time.
	RecycleWindow time.Duration

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

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)

Jump to

Keyboard shortcuts

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