sync

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: ISC Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[K comparable, T any] Sync[map[K]T]

Map is a map wrapped in a mutex for safe concurrent use

func NewMap

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

NewMap creates a new Sync object with an empty map

func (*Map[K, T]) BlockingSet added in v0.3.3

func (s *Map[K, T]) BlockingSet(fn func(val map[K]T) map[K]T)

func (*Map[K, T]) BlockingSetKey added in v0.3.4

func (s *Map[K, T]) BlockingSetKey(key K, fn func(val T) T)

func (*Map[K, T]) Copy

func (s *Map[K, T]) Copy() map[K]T

Copy returns a shallow copy of the wrapped map

func (*Map[K, T]) DeleteKey

func (s *Map[K, T]) DeleteKey(key K)

DeleteKey removes a key from the wrapped map

func (*Map[K, T]) Get

func (s *Map[K, T]) Get() map[K]T

Get is a wrapper to SyncMap.Copy for compatibility with Wrapped

func (*Map[K, T]) GetKey

func (s *Map[K, T]) GetKey(key K) (T, bool)

GetKey reads a key from the wrapper map

func (*Map[K, T]) Set

func (s *Map[K, T]) Set(val map[K]T)

Set allows to set the entire map at once, for compatibility with Wrapped

func (*Map[K, T]) SetKey

func (s *Map[K, T]) SetKey(key K, val T)

SetKey sets a value to the wrapped map

type RWSync

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

RWSync wraps any value in a RWMutex for safe concurrent use. Unlike Sync, concurrent read access is allowed (so don't use it for things like maps and pointers!)

func NewRWSync

func NewRWSync[T any](val T) *RWSync[T]

NewRWSync creates a new RWSync wrapper with a predefined value

func (*RWSync[T]) BlockingSet added in v0.3.4

func (s *RWSync[T]) BlockingSet(fn func(val T) T)

BlockingSet locks the value temporarily until a function has modified it

func (*RWSync[T]) Get

func (s *RWSync[T]) Get() T

Get reads the wrapped value contained

func (*RWSync[T]) Set

func (s *RWSync[T]) Set(val T)

Set sets the value wrapped by the object

type Slice

type Slice[T any] Sync[[]T]

Slice is a lice wrapped in a mutex for safe concurrent use

func NewSlice

func NewSlice[T any]() *Slice[T]

NewSlice creates a new Sync object with an empty slice

func (*Slice[T]) Clear

func (s *Slice[T]) Clear()

func (*Slice[T]) Copy

func (s *Slice[T]) Copy() []T

Copy returns a shallow copy of the wrapped slice

func (*Slice[T]) Get

func (s *Slice[T]) Get() []T

Get is a wrapper to SyncSlice.Copy for compatibility with Wrapped

func (*Slice[T]) GetIndex

func (s *Slice[T]) GetIndex(index int) T

func (*Slice[T]) Push

func (s *Slice[T]) Push(val T)

func (*Slice[T]) Set

func (s *Slice[T]) Set(val []T)

Set allows to set the entire slice at once, for compatibility with Wrapped

func (*Slice[T]) SetIndex

func (s *Slice[T]) SetIndex(index int, value T)

func (*Slice[T]) Size

func (s *Slice[T]) Size() int

func (*Slice[T]) Splice

func (s *Slice[T]) Splice(start int, length int) []T

type Sync

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

Sync wraps any value in a mutex for safe concurrent use

func NewSync

func NewSync[T any](val T) *Sync[T]

NewSync creates a new Sync wrapper with a predefined value

func (*Sync[T]) BlockingSet added in v0.3.4

func (s *Sync[T]) BlockingSet(fn func(val T) T)

BlockingSet locks the value temporarily until a function has modified it

func (*Sync[T]) Get

func (s *Sync[T]) Get() T

Get reads the wrapped value contained

func (*Sync[T]) Set

func (s *Sync[T]) Set(val T)

Set sets the value wrapped by the object

type Wrapped

type Wrapped[T any] interface {
	Get() T
	Set(T)
}

type WrappedMap

type WrappedMap[K comparable, V any] interface {
	Wrapped[map[K]V]
	GetKey(K) (V, bool)
	SetKey(K, V)
}

type WrappedSlice

type WrappedSlice[T any] interface {
	Wrapped[[]T]
	Size() int
	GetIndex(int) T
	SetIndex(int, T)
}

Jump to

Keyboard shortcuts

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