Documentation
¶
Overview ¶
Package typedsync is an alternative to the standard library's sync that uses type-parameters for type safety.
This package does not bother to duplicate documentation from the standard library's sync package; see sync's documentation for full documentation.
Besides requiring type parameters and such, typedsync is a drop-in replacement for sync.
Index ¶
- type Cond
- type Locker
- type Map
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) Load(key K) (value V, ok bool)
- func (m *Map[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (m *Map[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (m *Map[K, V]) Range(f func(key K, value V) bool)
- func (m *Map[K, V]) Store(key K, value V)
- type Mutex
- type Once
- type Pool
- type RWMutex
- type Value
- type WaitGroup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cond ¶
type Cond[T Locker] struct { L T // contains filtered or unexported fields }
Cond is a type-safe equivalent of the standard library's sync.Cond.
See the sync.Cond documentation for full details.
type Map ¶
type Map[K mapkey, V any] struct { // contains filtered or unexported fields }
Map is a type-safe equivalent of the standard library's sync.Map.
See the sync.Map documentation for full details.
Go 1.20 added sync.Map.Swap method; this method is only available on typedsync.Map if built with Go 1.20 or later.
Go 1.20 added sync.Map.CompareAndDelete and sync.Map.CompareAndSwap methods that are only usable if V is a comparable type; these methods are not available on typedsync.Map, but when typedsync is built with Go 1.20 or later they are available on a separate ComparableMap type.
When typedsync is built versions of Go prior to Go 1.20, typedsync.Map is specified too loosely, as
Map[K any, V any]
while with Go 1.20 and later, typedsync.Map is specified as
Map[K comparable, V any]
This is because with Go versions prior to 1.20, 'comparable' was overly strict, disallowing many types that are valid map-keys (see https://github.com/golang/go/issues/56548). The type used as K in a Map with older versions of Go must be a valid map-key type, even though the type specification of Map does not enforce that.
func (*Map[K, V]) LoadOrStore ¶
type Pool ¶
type Pool[T any] struct { New func() T // contains filtered or unexported fields }
Pool is a type-safe equivalent of the standard library's sync.Pool.
See the sync.Pool documentation for full details.
type Value ¶
type Value[T comparable] struct { // contains filtered or unexported fields }
Value is a type-safe equivalent of the standard library's sync/atomic.Value.
See the sync/atomic.Value documentation for full details.