syncwrap

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 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 Map

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

Map is a map safe for asynchronous use. It is just a ordinary map wrapped with a RWMutex.

func NewMap

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

func (*Map[K, V]) Get

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

Get retries a value from the synchronized map and returns success status and the value (or the zero-value of the given type if ok=false)

func (*Map[K, V]) Set

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

Set the value in the synchronized map

type SyncMap

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

SyncMap is a map safe for asynchronous use. Typefull wrapper around sync.Map

func (*SyncMap[K, V]) Load

func (m *SyncMap[K, V]) Load(key K) (value V, ok bool)

Load returns the value from the sync.Map. If ok=false the zero-value of the value-type is returned as value.

func (*SyncMap[K, V]) LoadOrStore

func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (result V, loaded bool)

LoadOrStore saves the value to the sync.Map if it is not already present. Returns the value currently present in the sync.Map. The return value loaded is true if the value has been loaded from the map and not been stored.

Jump to

Keyboard shortcuts

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