locks

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RWMap

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

RWMap is a simple wrapper around a map, with global Read-Write protection. For many concurrent reads/writes a sync.Map may be more performant, although it does not utilize Go generics. The RWMap does not have to be initialized, it is immediately ready for reads/writes.

func (*RWMap[K, V]) Clear

func (m *RWMap[K, V]) Clear()

Clear removes all key-value pairs from the map.

func (*RWMap[K, V]) Get

func (m *RWMap[K, V]) Get(key K) (value V, ok bool)

func (*RWMap[K, V]) Has

func (m *RWMap[K, V]) Has(key K) (ok bool)

func (*RWMap[K, V]) Range

func (m *RWMap[K, V]) Range(f func(key K, value V) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

func (*RWMap[K, V]) Set

func (m *RWMap[K, V]) Set(key K, value V)

type RWValue

type RWValue[E any] struct {
	sync.RWMutex
	Value E
}

RWValue is a simple container struct, to deconflict reads/writes of the value, without locking up a bigger structure in the caller. It exposes the underlying RWLock and Value for direct access where needed.

func (*RWValue[E]) Get

func (c *RWValue[E]) Get() (out E)

func (*RWValue[E]) Set

func (c *RWValue[E]) Set(v E)

Jump to

Keyboard shortcuts

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