Documentation ¶
Index ¶
- type DeepCopyable
- type Map
- func (m Map[K, V]) CancelWatch(key K)
- func (m Map[K, V]) DeepCopy() Map[K, V]
- func (m Map[K, V]) ForEachKey(f func(K) bool)
- func (m Map[K, V]) ForEachKeyE(f func(K) error) error
- func (m Map[K, V]) Get(key K) (V, bool)
- func (m Map[K, V]) InitWatch(key K, cancel func())
- func (m Map[K, V]) IsWatched(key K) bool
- func (m Map[K, V]) Len() int
- func (m Map[K, V]) Set(key K, val V) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeepCopyable ¶ added in v1.13.7
type DeepCopyable[T any] interface { DeepCopy() T }
DeepCopyable describes a type that implements the DeepCopy method to get a copy of itself that is safe to pass around without worrying about receivers modifying the original.
type Map ¶
type Map[K comparable, V DeepCopyable[V]] struct { M map[K]watchedVal[V] }
Map safely stores and retrieves values by validating that there is a live watch for a key. InitWatch must be called to associate a key with its cancel function before any Set's are called.
func NewMap ¶
func NewMap[K comparable, V DeepCopyable[V]]() Map[K, V]
func (Map[K, V]) CancelWatch ¶
func (m Map[K, V]) CancelWatch(key K)
CancelWatch first calls the cancel function associated with the key then deletes the key from the map. No-op if key is not present.
func (Map[K, V]) DeepCopy ¶ added in v1.13.7
DeepCopy returns a copy of the Map that is safe to be passed around without worrying about receivers modifying the original or canceling its watches.
func (Map[K, V]) ForEachKey ¶
ForEachKey iterates through the map, calling f for each iteration. It is up to the caller to Get the value and nil-check if required. Stops iterating if f returns false. Order of iteration is non-deterministic.
func (Map[K, V]) ForEachKeyE ¶
ForEachKeyE iterates through the map, calling f for each iteration. It is up to the caller to Get the value and nil-check if required. If a non-nil error is returned by f, iterating stops and the error is returned. Order of iteration is non-deterministic.
func (Map[K, V]) Get ¶
Get returns the underlying value for a key. If an entry has been set, returns (V, true). Otherwise, returns the zero value (V, false).
Note that even if InitWatch has been called for a key, unless Set has been called this function will return false.
func (Map[K, V]) InitWatch ¶
func (m Map[K, V]) InitWatch(key K, cancel func())
InitWatch associates a cancel function with a key, allowing Set to be called for the key. The cancel function is allowed to be nil.
Any existing data for a key will be cancelled and overwritten.