Skip to content
On this page

Index

Variables

go
var ErrPeriodicPoolMissingKey = errors.New("referenced key is missing")

type CachedFunc

Cached function type.

go
type CachedFunc[T any] func() (T, error)

func NewCachedFunc

go
func NewCachedFunc[T any](expire time.Duration, fn CachedFunc[T]) CachedFunc[T]

NewCachedFunc is a function wrapper with exprire duration setting. Consider it as a cached getter builder. As far as NewCachedFunc doesn't support functions with arguments (it will require much more effort and complications), you'll need to create cached getter for each argument set. At least, until the creation of more advanced cached builder.

Usage:

getter := NewCachedFunc(1 * time.Minute, func() (string, error) {
	time.Sleep(1 * time.Second) Imitate some work
	return "Function cached result"
})
log.Println(getter()) // Takes some time
log.Println(getter()) // Gets a value from cache

type PeriodicFunc

go
type PeriodicFunc[T any] func() (T, error)

func NewPeriodicFunc

go
func NewPeriodicFunc[T any](ctx context.Context, interval time.Duration, fn PeriodicFunc[T]) PeriodicFunc[T]

type PeriodicPool

go
type PeriodicPool[T any] struct {
    Pool    map[string]PeriodicFunc[T]
    Context context.Context //nolint:containedctx
}

func NewPeriodicPool

go
func NewPeriodicPool[T any](ctx context.Context) *PeriodicPool[T]

func (*PeriodicPool[T]) Get

go
func (p *PeriodicPool[T]) Get(key string) (T, error)

func (*PeriodicPool[T]) New

go
func (p *PeriodicPool[T]) New(key string, interval time.Duration, fn PeriodicFunc[T])

Generated by gomarkdoc