threadsafe

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package threadsafe contains generic containers that are protected either by Mutexes or atomics underneath the hood.

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 implements a simple thread-safe map protected by a mutex.

func NewThreadSafeMap

func NewThreadSafeMap[K comparable, V any](m map[K]V) *Map[K, V]

NewThreadSafeMap returns a thread-safe map instance from a normal map.

func (*Map[K, V]) Delete

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

Delete an item from a thread-safe map.

func (*Map[K, V]) Do

func (m *Map[K, V]) Do(fn func(mp map[K]V))

Do an action on the thread safe map

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(k K) (v V, ok bool)

Get an item from a thread-safe map.

func (*Map[K, V]) Keys

func (m *Map[K, V]) Keys() (r []K)

Keys returns the keys of a thread-safe map.

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() (l int)

Len of the thread-safe map.

func (*Map[K, V]) Put

func (m *Map[K, V]) Put(k K, v V)

Put an item into a thread-safe map.

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(fn func(k K, v V) bool)

Range runs the function fn(k K, v V) bool for each key value pair The keys are determined by a snapshot taken at the beginning of the range call If fn returns false, then the loop stops Only one invocation of fn will be active at one time, the iteration order is unspecified.

func (*Map[K, V]) View

func (m *Map[K, V]) View(fn func(mp map[K]V))

view an immutable snapshot of the map

Jump to

Keyboard shortcuts

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