sync

package
v1.1.0-dev.3 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 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 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