Documentation
¶
Index ¶
- type AsyncMap
- func (q *AsyncMap[T]) Add(id string, data T)
- func (q *AsyncMap[T]) Entries() []AsyncMapItem[T]
- func (q *AsyncMap[T]) Get(id string) *AsyncMapItem[T]
- func (q *AsyncMap[T]) Remove(id string)
- func (q *AsyncMap[T]) Set(id string, data T)
- func (q *AsyncMap[T]) SetCompleted(id string)
- func (q *AsyncMap[T]) SetFailed(id string)
- func (q *AsyncMap[T]) Subscribe() <-chan AsyncMapEvent[T]
- type AsyncMapEvent
- type AsyncMapEventAction
- type AsyncMapItem
- type Fanout
- type Map
- func (m Map[K, V]) Del(key K) bool
- func (m Map[K, V]) Entries() []MapEntry[K, V]
- func (m Map[K, V]) ForEach(fn func(value V, key K) error) error
- func (m Map[K, V]) Get(key K) *V
- func (m Map[K, V]) Has(key K) bool
- func (m Map[K, V]) Keys() []K
- func (m Map[K, V]) Len() int
- func (m Map[K, V]) Set(key K, value V) bool
- func (m Map[K, V]) Values() []V
- type MapEntry
- type Set
- func (s Set[T]) Add(values ...T)
- func (s Set[T]) Del(value T)
- func (left Set[T]) Difference(right Set[T]) Set[T]
- func (s Set[T]) Entries() []T
- func (s Set[T]) ForEach(fn func(element T) error) error
- func (s Set[T]) Has(value T) bool
- func (left Set[T]) Intersection(right Set[T]) Set[T]
- func (s Set[T]) Len() int
- func (left Set[T]) Union(right Set[T]) Set[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncMap ¶
type AsyncMap[T any] struct { // contains filtered or unexported fields }
a thread-safe map with subscribable events
func NewAsyncMap ¶
func NewAsyncMap[T any](initial ...map[string]AsyncMapItem[T]) *AsyncMap[T]
func (*AsyncMap[T]) Entries ¶
func (q *AsyncMap[T]) Entries() []AsyncMapItem[T]
returns a list of all items currently in the map
func (*AsyncMap[T]) Get ¶
func (q *AsyncMap[T]) Get(id string) *AsyncMapItem[T]
retrieves value by id
func (*AsyncMap[T]) SetCompleted ¶
sets the item as completed
func (*AsyncMap[T]) Subscribe ¶
func (q *AsyncMap[T]) Subscribe() <-chan AsyncMapEvent[T]
returns the event channel
use Fanout if you want multiple subscribers
type AsyncMapEvent ¶
type AsyncMapEvent[T any] struct { Action AsyncMapEventAction `json:"action"` Item AsyncMapItem[T] `json:"item"` }
the event emitted to subscribers
type AsyncMapEventAction ¶
type AsyncMapEventAction string
type of possible actions that may be emitted
const ( AddedEventAction AsyncMapEventAction = "added" CompletedEventAction AsyncMapEventAction = "completed" FailedEventAction AsyncMapEventAction = "failed" RemovedEventAction AsyncMapEventAction = "removed" )
type AsyncMapItem ¶
type AsyncMapItem[T any] struct { ID string `json:"id"` Completed bool `json:"completed"` Failed bool `json:"failed"` Data T `json:"data"` }
an element of the map
type Fanout ¶
type Fanout[T any] struct { // contains filtered or unexported fields }
thread-safe distributes events from an incoming channel into subscriber channels will be discarded, i.e. you will lose events if your subscriber can't keep up
func NewFanout ¶
create a new Fanout, creates a goroutine to broadcast when an incoming event is received
func (*Fanout[T]) Broadcast ¶
func (f *Fanout[T]) Broadcast(payload T)
send an event to all subscribers
func (*Fanout[T]) Unsubscribe ¶
remove channel from deliveries
type Map ¶
type Map[K comparable, V any] map[K]V
func NewMap ¶
func NewMap[K comparable, V any](initial ...map[K]V) Map[K, V]
Instantiates a new map, optionally copying in the entries of the given map
func (Map[K, V]) Del ¶
Deletes the value associated with the given key, returns true if a value was deleted
func (Map[K, V]) Get ¶
func (m Map[K, V]) Get(key K) *V
Retrieves the value associated with the given key or nil otherwise
type MapEntry ¶
type MapEntry[K comparable, V any] struct { Key K Value V }
type Set ¶
type Set[T comparable] map[T]struct{}
func NewSet ¶
func NewSet[T comparable](input ...T) Set[T]
Instantiates a new set, optionally filling with the given elements
func (Set[T]) Difference ¶
Creates a clone of the set and removes the elements from the given set
i.e. left - right
func (Set[T]) Intersection ¶
Creates a clone of the set and merges the elements of the given
i.e. left ∩ right