sync

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrentSlice added in v1.0.0

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

ConcurrentSlice is a thread-safe slice.

It is safe to use from multiple goroutines without additional locking. It should be referenced by pointer.

Initialize using NewConcurrentSlice().

func NewConcurrentSlice added in v1.0.0

func NewConcurrentSlice[T any](initial ...T) *ConcurrentSlice[T]

NewConcurrentSlice creates a new thread-safe slice.

func (*ConcurrentSlice[T]) Append added in v1.0.0

func (s *ConcurrentSlice[T]) Append(val ...T)

Append adds an element to the slice

func (*ConcurrentSlice[T]) Copy added in v1.0.0

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

Copy returns a new deep copy of concurrentSlice with the same elements

func (*ConcurrentSlice[T]) Get added in v1.0.0

func (s *ConcurrentSlice[T]) Get(index int) T

Get returns the value at the given index

func (*ConcurrentSlice[T]) Len added in v1.0.0

func (s *ConcurrentSlice[T]) Len() int

Len returns the length of the slice

func (*ConcurrentSlice[T]) MarshalJSON added in v1.0.0

func (cs *ConcurrentSlice[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ConcurrentSlice[T]) Reset added in v1.0.0

func (s *ConcurrentSlice[T]) Reset()

Reset removes all elements from the slice

func (*ConcurrentSlice[T]) Set added in v1.0.0

func (s *ConcurrentSlice[T]) Set(index int, val T)

Set updates the value at the given index. If the index is greater than the length of the slice, it panics. If the index is equal to the length of the slice, the value is appended. Otherwise, the value at the index is updated.

func (*ConcurrentSlice[T]) String added in v1.0.0

func (cs *ConcurrentSlice[T]) String() string

func (*ConcurrentSlice[T]) ToSlice added in v1.0.0

func (s *ConcurrentSlice[T]) ToSlice() []T

ToSlice returns a copy of the underlying slice

func (*ConcurrentSlice[T]) UnmarshalJSON added in v1.0.0

func (cs *ConcurrentSlice[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Mtx added in v1.5.0

type Mtx interface {
	Lock()
	Unlock()
}

Mtx is a mutex interface. Implemented by sync.Mutex and deadlock.Mutex.

type RMtx added in v1.5.0

type RMtx interface {
	RLock()
	RUnlock()
}

RMtx is a mutex that can be locked for read.

Implemented by sync.RwMutex and deadlock.RwMutex.

type UnlockFn added in v1.5.0

type UnlockFn func() bool

UnlockFn is a function that unlocks a mutex. It returns true if the mutex was unlocked, false if it was already unlocked.

func LockGuard added in v1.5.0

func LockGuard(mtx Mtx) UnlockFn

LockGuard locks the mutex and returns a function that unlocks it. The returned function must be called to release the lock. The returned function may be called multiple times - only the first call will unlock the mutex, others will be no-ops.

func RLockGuard added in v1.5.0

func RLockGuard(mtx RMtx) UnlockFn

RLockGuard locks the read-write mutex for reading and returns a function that unlocks it. The returned function must be called to release the lock. The returned function may be called multiple times - only the first call will unlock the mutex, others will be no-ops.

type Waker

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

Waker is used to wake up a sleeper when some event occurs. It debounces multiple wakeup calls occurring between each sleep, and wakeups are non-blocking to avoid having to coordinate goroutines.

func NewWaker

func NewWaker() *Waker

NewWaker creates a new Waker.

func (*Waker) Close

func (w *Waker) Close() error

Close closes the waker and cleans up its resources

func (*Waker) Sleep

func (w *Waker) Sleep() <-chan struct{}

Sleep returns a channel that blocks until Wake() is called.

func (*Waker) Wake

func (w *Waker) Wake()

Wake wakes up the sleeper.

func (*Waker) WakeAfter

func (w *Waker) WakeAfter(delay time.Duration)

WakeAfter wakes up the sleeper after some delay.

Jump to

Keyboard shortcuts

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