typedsync

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: GPL-2.0-or-later Imports: 1 Imported by: 1

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

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.

func NewCond

func NewCond[T Locker](l T) *Cond[T]

func (*Cond[T]) Broadcast

func (c *Cond[T]) Broadcast()

func (*Cond[T]) Signal

func (c *Cond[T]) Signal()

func (*Cond[T]) Wait

func (c *Cond[T]) Wait()

type Locker

type Locker = sync.Locker

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]) Delete

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

func (*Map[K, V]) Load

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

func (*Map[K, V]) LoadAndDelete

func (m *Map[K, V]) LoadAndDelete(key K) (value V, loaded bool)

func (*Map[K, V]) LoadOrStore

func (m *Map[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

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)

type Mutex

type Mutex = sync.Mutex

type Once

type Once = sync.Once

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.

func (*Pool[T]) Get

func (p *Pool[T]) Get() (val T, ok bool)

func (*Pool[T]) Put

func (p *Pool[T]) Put(val T)

type RWMutex

type RWMutex = sync.RWMutex

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.

func (*Value[T]) CompareAndSwap

func (v *Value[T]) CompareAndSwap(oldV, newV T) (swapped bool)

func (*Value[T]) Load

func (v *Value[T]) Load() (val T, ok bool)

func (*Value[T]) Store

func (v *Value[T]) Store(val T)

func (*Value[T]) Swap

func (v *Value[T]) Swap(newV T) (oldV T, oldOK bool)

type WaitGroup

type WaitGroup = sync.WaitGroup

Jump to

Keyboard shortcuts

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