pool

package
v3.80.13 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLimit = 50
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

type Item

type Item interface {
	IsAlive() bool
	Close(ctx context.Context) error
}

type ItemConstraint

type ItemConstraint[T any] interface {
	*T
	Item
}

type Option

type Option[PT ItemConstraint[T], T any] func(c *Config[PT, T])

func WithClock

func WithClock[PT ItemConstraint[T], T any](clock clockwork.Clock) Option[PT, T]

func WithCloseItemTimeout

func WithCloseItemTimeout[PT ItemConstraint[T], T any](t time.Duration) Option[PT, T]

func WithCreateItemFunc

func WithCreateItemFunc[PT ItemConstraint[T], T any](f func(ctx context.Context) (PT, error)) Option[PT, T]

func WithCreateItemTimeout

func WithCreateItemTimeout[PT ItemConstraint[T], T any](t time.Duration) Option[PT, T]

func WithIdleTimeToLive

func WithIdleTimeToLive[PT ItemConstraint[T], T any](idleTTL time.Duration) Option[PT, T]

func WithItemUsageLimit

func WithItemUsageLimit[PT ItemConstraint[T], T any](itemUsageLimit uint64) Option[PT, T]

func WithLimit

func WithLimit[PT ItemConstraint[T], T any](size int) Option[PT, T]

func WithSyncCloseItem

func WithSyncCloseItem[PT ItemConstraint[T], T any]() Option[PT, T]

func WithTrace

func WithTrace[PT ItemConstraint[T], T any](t *Trace) Option[PT, T]

type Pool

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

func New

func New[PT ItemConstraint[T], T any](
	ctx context.Context,
	opts ...Option[PT, T],
) *Pool[PT, T]

func (*Pool[PT, T]) Close

func (p *Pool[PT, T]) Close(ctx context.Context) (finalErr error)

func (*Pool[PT, T]) Stats

func (p *Pool[PT, T]) Stats() Stats

func (*Pool[PT, T]) With

func (p *Pool[PT, T]) With(
	ctx context.Context,
	f func(ctx context.Context, item PT) error,
	opts ...retry.Option,
) (finalErr error)

type Stats

type Stats struct {
	Limit            int
	Index            int
	Idle             int
	Wait             int
	CreateInProgress int
}

type Trace

type Trace struct {
	OnNew   func(ctx *context.Context, call stack.Caller) func(limit int)
	OnClose func(ctx *context.Context, call stack.Caller) func(err error)
	OnTry   func(ctx *context.Context, call stack.Caller) func(err error)
	OnWith  func(ctx *context.Context, call stack.Caller) func(attempts int, err error)
	OnPut   func(ctx *context.Context, call stack.Caller, item any) func(err error)
	OnGet   func(ctx *context.Context, call stack.Caller) func(item any, attempts int, err error)

	OnChange func(Stats)
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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