syncutil

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package syncutil provides synchronization primitives.

Values containing the types defined in this package should not be copied.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map added in v0.0.15

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

Map is a wrapper around a map[K]V that is safe for concurrent use by multiple goroutines.

func (*Map[K, V]) Clear added in v0.0.15

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

Clear deletes all the entries, resulting in an empty Map.

func (*Map[K, V]) Delete added in v0.0.15

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

Delete deletes the value for a key.

func (*Map[K, V]) Iter added in v0.0.15

func (m *Map[K, V]) Iter() iter.Seq2[K, V]

Iter locks m and returns an iterator over entries of m. Once iteration is complete, m will be unlocked.

func (*Map[K, V]) Load added in v0.0.15

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

Load returns the value stored in the map for a key, or the zero value of V if no value is present. The ok result indicates whether value was found in the map.

func (*Map[K, V]) Make added in v0.0.15

func (m *Map[K, V]) Make()

Make is the concurrency-safe equivalent of make(map[K]V)

func (*Map[K, V]) MakeSize added in v0.0.15

func (m *Map[K, V]) MakeSize(n int)

MakeSize is the concurrency-safe equivalent of make(map[K]V, n)

func (*Map[K, V]) MarshalJSON added in v0.0.15

func (m *Map[K, V]) MarshalJSON() ([]byte, error)

func (*Map[K, V]) Store added in v0.0.15

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

Store sets the value for a key.

func (*Map[K, V]) Swap added in v0.0.15

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

Swap swaps the value for a key and returns the previous value if any. The loaded result reports whether the key was present.

func (*Map[K, V]) UnmarshalJSON added in v0.0.15

func (m *Map[K, V]) UnmarshalJSON(b []byte) error

type Once

type Once struct {
	// contains filtered or unexported fields
}

Once is equivalent to sync.Once with the ability to be reset.

func (*Once) Do

func (o *Once) Do(f func())

Do calls the function f if and only if Do is being called for the first time for this instance of Once.

func (*Once) Reset

func (o *Once) Reset() bool

Reset resets o to be reused.

type OnceValue added in v0.0.15

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

OnceValue is the struct equivalent of sync.OnceValue with the ability to be reset.

func (*OnceValue[T]) Do added in v0.0.15

func (o *OnceValue[T]) Do(f func() T) T

type OnceValues added in v0.0.15

type OnceValues[T1, T2 any] struct {
	Once
	// contains filtered or unexported fields
}

OnceValues is the struct equivalent of sync.OnceValues with the ability to be reset.

func (*OnceValues[T1, T2]) Do added in v0.0.15

func (o *OnceValues[T1, T2]) Do(f func() (T1, T2)) (T1, T2)

Jump to

Keyboard shortcuts

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