atomic

package
v0.36.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedVariable

type CachedVariable[T any] struct {
	// contains filtered or unexported fields
}

CachedVariable is an atomic cached variable. It will store a value for the specified lifetime and allow retrieval of the value.

func NewCachedVariable

func NewCachedVariable[T any](lifetime time.Duration) *CachedVariable[T]

NewCachedVariable creates a new cached variable with a given lifetime.

func (*CachedVariable[T]) Get

func (c *CachedVariable[T]) Get() (T, bool)

Get returns the value if possible and a boolean indicating if the value was available.

func (*CachedVariable[T]) Reset

func (c *CachedVariable[T]) Reset()

Reset resets the cached variable so that it no longer stores a value.

func (*CachedVariable[T]) Set

func (c *CachedVariable[T]) Set(v T)

Set sets the value and resets the lifetime.

type Lazy

type Lazy[T any] struct {
	Resolve func(context.Context) (T, error)
	// contains filtered or unexported fields
}

Lazy persistently stores a value in memory by evaluating the Resolve function when the value is accessed

func (*Lazy[T]) Set

func (c *Lazy[T]) Set(v T)

Set assigns the passed value

func (*Lazy[T]) TryGet

func (c *Lazy[T]) TryGet(ctx context.Context, opts ...functional.Option[Options]) (T, error)

TryGet attempts to get a non-nil value from the internal value. If the internal value is nil, the Resolve function will attempt to resolve the value, setting the value to be persistently stored if the resolve of Resolve is non-nil.

type Options

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

func IgnoreCacheOption

func IgnoreCacheOption(o Options) Options

type Slice

type Slice[T any] struct {
	// contains filtered or unexported fields
}

Slice exposes a slice of a type in a race-free manner.

func (*Slice[T]) Add

func (a *Slice[T]) Add(input T)

func (*Slice[T]) Len

func (a *Slice[T]) Len() int

func (*Slice[T]) Range

func (a *Slice[T]) Range(f func(pool T) bool)

func (*Slice[T]) Reset

func (a *Slice[T]) Reset()

func (*Slice[T]) Set

func (a *Slice[T]) Set(values []T)

Jump to

Keyboard shortcuts

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