tracker

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tracker

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

Tracker is a concurrency-safe map wrapper for tracking live objects like containers or services.

It uses a sync.RWMutex to guard access to its internal map. The zero value of tracker is ready to use; calling Set() will lazily initialize the internal map if needed.

The type parameter T can be either a value type (e.g. int, struct) or a pointer type (e.g. *ContainerConfig). Use pointers if T contains fields that should not be copied (for example tombs, mutexes, or loggers).

func NewTracker

func NewTracker[T any]() *Tracker[T]

NewTracker creates and initializes a new tracker for type T.

While the zero value of Tracker is ready to use, using the constructor is recommended in case future versions require explicit initialization.

func (*Tracker[T]) Clear

func (t *Tracker[T]) Clear() map[string]T

Clear removes all tracked items and returns a snapshot of the previous contents.

The returned map is a shallow copy of the internal state at the time of the call, so further modifications to it do not affect the tracker.

func (*Tracker[T]) Delete

func (t *Tracker[T]) Delete(id string)

Delete removes the item with the given id, if present.

func (*Tracker[T]) Get

func (t *Tracker[T]) Get(id string) (T, bool)

Get returns the item stored under the given id, along with a boolean indicating whether it was found.

func (*Tracker[T]) GetAll

func (t *Tracker[T]) GetAll() map[string]T

GetAll returns a snapshot copy of all items currently in the tracker.

The returned map is a shallow copy: modifying it will not affect the underlying tracker contents. Safe for concurrent use.

func (*Tracker[T]) Len

func (t *Tracker[T]) Len() int

Len returns the number of items currently stored in the tracker.

func (*Tracker[T]) Set

func (t *Tracker[T]) Set(id string, item T)

Set stores item under the given id. If the tracker map is nil, it will lazily initialize it.

Jump to

Keyboard shortcuts

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