concurrency

package
v2.17.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartSupervised

func StartSupervised(ctx context.Context, label string, run func(context.Context) error) (func(context.Context) error, error)

StartSupervised starts a background operation and returns its cancel-and-join function.

Types

type Signal

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

Signal delivers each published value once to every current subscriber. Subscribers run sequentially on the publishing goroutine.

func NewSignal

func NewSignal[T any]() *Signal[T]

NewSignal creates an empty typed signal.

func (*Signal[T]) Publish

func (s *Signal[T]) Publish(value T)

Publish synchronously delivers value without holding the subscriber lock.

func (*Signal[T]) Subscribe

func (s *Signal[T]) Subscribe(callback func(T)) func()

Subscribe registers a callback and returns an idempotent unsubscribe function.

type Snapshot

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

Snapshot publishes immutable copies of a value for lock-free readers.

func (*Snapshot[T]) Load

func (s *Snapshot[T]) Load() (T, bool)

Load returns a copy of the latest published value.

func (*Snapshot[T]) Store

func (s *Snapshot[T]) Store(value T)

Store replaces the published value with an immutable copy.

type StateMap

type StateMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

StateMap owns mutable keyed state while publishing immutable snapshots for readers.

func NewStateMap

func NewStateMap[K comparable, V any]() *StateMap[K, V]

NewStateMap creates a locally serialized state map for process-local state.

func (*StateMap[K, V]) Apply

func (s *StateMap[K, V]) Apply(ctx context.Context, label string, mutate func(map[K]V) (changed bool, err error)) error

Apply serializes a mutation and publishes it atomically when changed is true.

func (*StateMap[K, V]) ApplyTyped

func (s *StateMap[K, V]) ApplyTyped[R any](
	ctx context.Context,
	label string,
	mutate func(map[K]V) (result R, changed bool, err error),
) (R, error)

ApplyTyped serializes a typed mutation and publishes its resulting state.

func (*StateMap[K, V]) Drain

func (s *StateMap[K, V]) Drain(ctx context.Context, label string) ([]V, error)

Drain atomically removes and returns every value.

func (*StateMap[K, V]) Get

func (s *StateMap[K, V]) Get(key K) (V, bool)

Get reads one value from the latest immutable snapshot without acquiring the mutation lock.

func (*StateMap[K, V]) Remove

func (s *StateMap[K, V]) Remove(ctx context.Context, label string, key K) (V, bool, error)

Remove deletes and returns one value.

func (*StateMap[K, V]) RemoveWhere

func (s *StateMap[K, V]) RemoveWhere(ctx context.Context, label string, predicate func(K, V) bool) ([]V, error)

RemoveWhere atomically removes every value selected by predicate.

func (*StateMap[K, V]) Store

func (s *StateMap[K, V]) Store(ctx context.Context, label string, key K, value V) (V, bool, error)

Store publishes a value and returns the value it replaced, if any.

func (*StateMap[K, V]) Values

func (s *StateMap[K, V]) Values() []V

Values reads every value from the latest immutable snapshot.

Jump to

Keyboard shortcuts

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