package exsync
import "go.mau.fi/util/exsync"
Index ¶
- Variables
- func MapRingBuffer[Key comparable, Value, Output any](rb *RingBuffer[Key, Value], callback func(key Key, val Value) (Output, error)) ([]Output, error)
- type Event
- func NewEvent() *Event
- func (e *Event) Clear()
- func (e *Event) GetChan() EventChan
- func (e *Event) IsSet() bool
- func (e *Event) Set()
- func (e *Event) Wait(ctx context.Context) error
- func (e *Event) WaitTimeout(timeout time.Duration) bool
- type EventChan
- type Map
- func NewMap[Key comparable, Value any]() *Map[Key, Value]
- func (sm *Map[Key, Value]) Clone() *Map[Key, Value]
- func (sm *Map[Key, Value]) CopyData() map[Key]Value
- func (sm *Map[Key, Value]) Delete(key Key)
- func (sm *Map[Key, Value]) Get(key Key) (value Value, ok bool)
- func (sm *Map[Key, Value]) GetOrSet(key Key, value Value) (actual Value, wasGet bool)
- func (sm *Map[Key, Value]) Pop(key Key) (value Value, ok bool)
- func (sm *Map[Key, Value]) Set(key Key, value Value)
- func (sm *Map[Key, Value]) Swap(key Key, value Value) (oldValue Value, wasReplaced bool)
- type ReturnableOnce
- type RingBuffer
- func NewRingBuffer[Key comparable, Value any](size int) *RingBuffer[Key, Value]
- func (rb *RingBuffer[Key, Value]) Contains(val Key) bool
- func (rb *RingBuffer[Key, Value]) Get(key Key) (val Value, found bool)
- func (rb *RingBuffer[Key, Value]) Iter(callback func(key Key, val Value) error) error
- func (rb *RingBuffer[Key, Value]) Push(key Key, val Value)
- func (rb *RingBuffer[Key, Value]) Replace(key Key, val Value) bool
- func (rb *RingBuffer[Key, Value]) Size() int
- type Set
- func NewSet[T comparable]() *Set[T]
- func NewSetWithItems[T comparable](items []T) *Set[T]
- func NewSetWithMap[T comparable](m map[T]empty) *Set[T]
- func NewSetWithSize[T comparable](size int) *Set[T]
- func (s *Set[T]) Add(item T) bool
- func (s *Set[T]) AsList() []T
- func (s *Set[T]) Has(item T) bool
- func (s *Set[T]) Pop(item T) bool
- func (s *Set[T]) Remove(item T)
- func (s *Set[T]) ReplaceAll(newSet *Set[T])
- func (s *Set[T]) Size() int
Variables ¶
var ( // StopIteration can be returned by the RingBuffer.Iter or MapRingBuffer callbacks to stop iteration immediately. StopIteration = errors.New("stop iteration") //lint:ignore ST1012 not an error // SkipItem can be returned by the MapRingBuffer callback to skip adding a specific item. SkipItem = errors.New("skip item") //lint:ignore ST1012 not an error )
Functions ¶
func MapRingBuffer ¶
func MapRingBuffer[Key comparable, Value, Output any](rb *RingBuffer[Key, Value], callback func(key Key, val Value) (Output, error)) ([]Output, error)
Types ¶
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event is a wrapper around a channel that can be used to notify multiple waiters that some event has happened.
It's modelled after Python's asyncio.Event: https://docs.python.org/3/library/asyncio-sync.html#asyncio.Event
func NewEvent ¶
func NewEvent() *Event
NewEvent creates a new event. It will initially be unset.
func (*Event) Clear ¶
func (e *Event) Clear()
Clear clears the event, making it unset. Future calls to Wait will now block until Set is called again. If the event is not already set, this is a no-op and existing calls to Wait will keep working.
func (*Event) GetChan ¶
GetChan returns the channel that will be closed when the event is set.
func (*Event) IsSet ¶
IsSet returns true if the event has been set.
func (*Event) Set ¶
func (e *Event) Set()
Set sets the event, notifying all waiters.
func (*Event) Wait ¶
Wait waits for either the event to happen or the given context to be done. If the context is done first, the error is returned, otherwise the return value is nil.
func (*Event) WaitTimeout ¶
WaitTimeout waits for either the event to happen within the given timeout. If the timeout expires first, the return value is false, otherwise it's true.
type EventChan ¶
type EventChan = <-chan empty
type Map ¶
type Map[Key comparable, Value any] struct { // contains filtered or unexported fields }
Map is a simple map with a built-in mutex.
func NewMap ¶
func NewMap[Key comparable, Value any]() *Map[Key, Value]
func (*Map[Key, Value]) Clone ¶
Clone returns a copy of the map.
func (*Map[Key, Value]) CopyData ¶
func (sm *Map[Key, Value]) CopyData() map[Key]Value
CopyData returns a copy of the data in the map as a normal (non-atomic) map.
func (*Map[Key, Value]) Delete ¶
func (sm *Map[Key, Value]) Delete(key Key)
Delete removes a key from the map.
func (*Map[Key, Value]) Get ¶
Get gets a value in the map.
The boolean return parameter is the same as with normal Go map access (true if the key exists, false if not).
func (*Map[Key, Value]) GetOrSet ¶
GetOrSet gets a value in the map if the key already exists, otherwise inserts the given value and returns it.
The boolean return parameter is true if the key already exists, and false if the given value was inserted.
func (*Map[Key, Value]) Pop ¶
Pop removes a key from the map and returns the old value.
The boolean return parameter is the same as with normal Go map access (true if the key exists, false if not).
func (*Map[Key, Value]) Set ¶
func (sm *Map[Key, Value]) Set(key Key, value Value)
Set stores a value in the map.
func (*Map[Key, Value]) Swap ¶
Swap sets a value in the map and returns the old value.
The boolean return parameter is true if the value already existed, false if not.
type ReturnableOnce ¶
type ReturnableOnce[Value any] struct { // contains filtered or unexported fields }
ReturnableOnce is a wrapper for sync.Once that can return a value
Deprecated: Use sync.OnceValues instead.
func (*ReturnableOnce[Value]) Do ¶
func (ronce *ReturnableOnce[Value]) Do(fn func() (Value, error)) (Value, error)
type RingBuffer ¶
type RingBuffer[Key comparable, Value any] struct { // contains filtered or unexported fields }
func NewRingBuffer ¶
func NewRingBuffer[Key comparable, Value any](size int) *RingBuffer[Key, Value]
func (*RingBuffer[Key, Value]) Contains ¶
func (rb *RingBuffer[Key, Value]) Contains(val Key) bool
func (*RingBuffer[Key, Value]) Get ¶
func (rb *RingBuffer[Key, Value]) Get(key Key) (val Value, found bool)
func (*RingBuffer[Key, Value]) Iter ¶
func (rb *RingBuffer[Key, Value]) Iter(callback func(key Key, val Value) error) error
func (*RingBuffer[Key, Value]) Push ¶
func (rb *RingBuffer[Key, Value]) Push(key Key, val Value)
func (*RingBuffer[Key, Value]) Replace ¶
func (rb *RingBuffer[Key, Value]) Replace(key Key, val Value) bool
func (*RingBuffer[Key, Value]) Size ¶
func (rb *RingBuffer[Key, Value]) Size() int
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set is a wrapper around a map[T]struct{} with a built-in mutex.
func NewSet ¶
func NewSet[T comparable]() *Set[T]
NewSet constructs a Set with an empty map.
func NewSetWithItems ¶
func NewSetWithItems[T comparable](items []T) *Set[T]
NewSetWithItems constructs a Set with items from the given slice pre-filled. The slice is not modified or used after the function returns, so using it after this is safe.
func NewSetWithMap ¶
func NewSetWithMap[T comparable](m map[T]empty) *Set[T]
NewSetWithMap constructs a Set with the given map. Accessing the map directly after passing it here is not safe.
func NewSetWithSize ¶
func NewSetWithSize[T comparable](size int) *Set[T]
NewSetWithSize constructs a Set with a map that has been allocated the given amount of space.
func (*Set[T]) Add ¶
Add adds an item to the set. The return value is true if the item was added to the set, or false otherwise.
func (*Set[T]) AsList ¶
func (s *Set[T]) AsList() []T
func (*Set[T]) Has ¶
Has checks if the given item is in the set.
func (*Set[T]) Pop ¶
Pop removes the given item from the set. The return value is true if the item was in the set, or false otherwise.
func (*Set[T]) Remove ¶
func (s *Set[T]) Remove(item T)
Remove removes the given item from the set.
func (*Set[T]) ReplaceAll ¶
ReplaceAll replaces this set with the given set. If the given set is nil, the set is cleared.
func (*Set[T]) Size ¶
Source Files ¶
event.go returnonce.go ringbuffer.go syncmap.go syncset.go
- Version
- v0.8.6 (latest)
- Published
- Mar 16, 2025
- Platform
- linux/amd64
- Imports
- 4 packages
- Last checked
- 1 week ago –
Tools for package owners.