sync

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NewCond  = sync.NewCond
	OnceFunc = sync.OnceFunc
)

Functions

Functions

func OnceValue

func OnceValue[T any](f func() T) func() T

func OnceValues

func OnceValues[T1, T2 any](f func() (T1, T2)) func() (T1, T2)

func Sleep

func Sleep(ctx context.Context, duration time.Duration) error

Sleep sleeps for the specified duration or until the context is done. If it was the context that was done first, it returns the error that caused it using context.Cause.

Types

type Cond

type Cond = sync.Cond

Types

type Map

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

Map is a thread-safe generic map implementation on top of sync.Map

func NewMap

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

func (*Map[K, V]) Clear

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

func (*Map[K, V]) Delete

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

func (*Map[K, V]) Keys

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

func (*Map[K, V]) Load

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

func (*Map[K, V]) LoadOrStore

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

func (*Map[K, V]) LoadOrStoreFunc

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

LoadOrStoreFunc loads the value for the given key, if it exists. If the key does not exist, it calls the generator function to create the value and stores it in the map. The generator function is guaranteed to be called synchronously and only once for the same key.

func (*Map[K, V]) Range

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

func (*Map[K, V]) Store

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

func (*Map[K, V]) Values

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

type Mutex

type Mutex = sync.Mutex

Types

type Once

type Once = sync.Once

Types

type Pool

type Pool = sync.Pool

Types

type RWMutex

type RWMutex = sync.RWMutex

Types

type WaitGroup

type WaitGroup = sync.WaitGroup

Types

Jump to

Keyboard shortcuts

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