syncro

package
v0.0.0-...-c443d34 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 2 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyExists = fmt.Errorf("map key already exists")

Functions

This section is empty.

Types

type Map

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

Map is a thread-safe generic map type

func NewMap

func NewMap[K comparable, V any](initMap map[K]V) Map[K, V]

NewMap constructs a new syncro.Map, initialized from a Go map. It is not necessary to use NewMap if you do not need to set an initial value.

func (*Map[K, V]) Create

func (m *Map[K, V]) Create(key K, value V) error

Create stores a value into the map, which must not already exist. Returns ErrAlreadyExists if the key exists.

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

Delete a value from the map

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(key K) (V, bool)

Get a value from the map. If it exists, returns the value and true; otherwise, returns the zero value and false.

func (*Map[K, V]) Set

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

Set stores a value into the map

func (*Map[K, V]) WorkWith

func (m *Map[K, V]) WorkWith(f func(*map[K]V))

WorkWith calls a function to work with the map under lock

func (*Map[K, V]) WorkWithReadOnly

func (m *Map[K, V]) WorkWithReadOnly(f func(map[K]V))

WorkWithReadOnly calls a function to work with the map under lock. You are on the honor system not to change it.

type Var

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

Var stores a single variable and allows synchronized access

func NewVar

func NewVar[T any](value T) Var[T]

NewVar creates a new variable with a given initial value. It is not required to use NewVar if you don't need to set an initial value.

func (*Var[T]) Get

func (sv *Var[T]) Get() T

Get retrieves the value

func (*Var[T]) Set

func (sv *Var[T]) Set(value T)

Set sets the value

func (*Var[T]) WorkWith

func (sv *Var[T]) WorkWith(f func(*T))

WorkWith calls a function to work with the data under lock

func (*Var[T]) WorkWithReadOnly

func (sv *Var[T]) WorkWithReadOnly(f func(T))

WorkWithReadOnly calls a function to work with the data under lock. You are on the honor system not to change it.

Jump to

Keyboard shortcuts

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