renew

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const TmpTrackerPrefix = "tmp/"

TmpTrackerPrefix is the tracker prefix for temporary objects.

Variables

This section is empty.

Functions

func NewTmpDeleter

func NewTmpDeleter() track.Deleter

NewTmpDeleter creates a new temporary deleter.

func WithStringSet

func WithStringSet(ctx context.Context, ttl time.Duration, rf RenewFunc, cf ComposeFunc, cb func(ctx context.Context, ss *StringSet) error) (retErr error)

WithStringSet creates a StringSet using ttl and rf. It calls cb with the StringSets context and the new StringSet. If ctx is cancelled, the StringSet will be Closed, and the cancellation will propagate down to the context passed to cb.

Types

type ComposeFunc

type ComposeFunc = func(ctx context.Context, xs []string, ttl time.Duration) (string, error)

ComposeFunc is the type of a function used to compose a set of strings

func NewTmpComposer

func NewTmpComposer(tr track.Tracker, name string) ComposeFunc

NewTmpComposer returns a ComposeFunc which creates meaningless temporary objects Use NewTmpDeleter to get a no-op track.Deleter to handle these objects.

type Func

type Func func(ctx context.Context, ttl time.Duration) error

Func is a function called to renew something for ttl time.

type RenewFunc

type RenewFunc = func(ctx context.Context, x string, ttl time.Duration) error

RenewFunc is the type of a function used to renew a string

type Renewer

type Renewer struct {
	// contains filtered or unexported fields
}

Renewer manages renewing something in the background

func NewRenewer

func NewRenewer(ctx context.Context, ttl time.Duration, renewFunc Func) *Renewer

NewRenewer returns a renewer that will call renewFunc with ttl every period; where period will be some fraction ttl. If ctx is cancelled the renewer will be closed.

func (*Renewer) Close

func (r *Renewer) Close() error

Close closes the renewer, stopping the background renewal. Close is idempotent.

func (*Renewer) Context

func (r *Renewer) Context() context.Context

Context returns a context which will be cancelled when the renewer is closed

type StringSet

type StringSet struct {
	*Renewer
	// contains filtered or unexported fields
}

StringSet renews a set of strings until it is closed

func NewStringSet

func NewStringSet(ctx context.Context, ttl time.Duration, renewFunc RenewFunc, composeFunc ComposeFunc) *StringSet

NewStringSet returns a StringSet it will renew every string in the set for ttl each period. See Renewer

func (*StringSet) Add

func (ss *StringSet) Add(ctx context.Context, x string) error

Add adds x to the set of strings being renewed

func (*StringSet) Compose

func (ss *StringSet) Compose(ctx context.Context) (string, error)

Compose returns the result of a compose call on all of the strings being renewed.

Jump to

Keyboard shortcuts

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