Documentation ¶
Index ¶
- type Locker
- type Observer
- type ReactiveObserver
- type SafeMap
- func (sm *SafeMap[T, U]) Clear()
- func (sm *SafeMap[T, U]) Copy() uc.Copier
- func (sm *SafeMap[T, U]) Delete(key T)
- func (sm *SafeMap[T, U]) Get(key T) (U, bool)
- func (sm *SafeMap[T, U]) GetMap() map[T]U
- func (sm *SafeMap[T, U]) Iterator() ui.Iterater[*uc.Pair[T, U]]
- func (sm *SafeMap[T, U]) Len() int
- func (sm *SafeMap[T, U]) Scan(f ScanFunc[T, U]) (bool, error)
- func (sm *SafeMap[T, U]) Set(key T, val U)
- type ScanFunc
- type Subject
- func (s *Subject[T]) Attach(o Observer[T])
- func (s *Subject[T]) Copy() uc.Copier
- func (s *Subject[T]) DoRead(f func(T))
- func (s *Subject[T]) Get() T
- func (s *Subject[T]) ModifyState(f func(T) T)
- func (s *Subject[T]) NotifyAll()
- func (s *Subject[T]) Set(state T)
- func (s *Subject[T]) SetObserver(action func(T))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Locker ¶ added in v0.2.39
Locker is a thread-safe locker that allows multiple goroutines to wait for a condition.
func NewLocker ¶ added in v0.2.39
NewLocker creates a new Locker.
Use Locker.Set for observer boolean predicates.
Parameters:
- keys: The keys to initialize the locker.
Returns:
- *Locker[T]: A new Locker.
Behaviors:
- All the predicates are initialized to true.
func (*Locker[T]) ChangeValue ¶ added in v0.3.18
ChangeValue changes the value of a subject.
Parameters:
- key: The key to change the value.
- value: The new value.
Returns:
- bool: True if the key exists, false otherwise.
func (*Locker[T]) DoFunc ¶ added in v0.3.18
DoFunc is a function that executes a function while waiting for the condition to be false.
Parameters:
- f: The function to execute that takes a map of conditions as a parameter and returns true if the function should exit, false otherwise.
Returns:
- bool: True if the function should exit, false otherwise.
func (*Locker[T]) Get ¶ added in v0.3.17
Get returns the value of a predicate.
Parameters:
- key: The key to get the value.
Returns:
- bool: The value of the predicate.
- bool: True if the key exists, false otherwise.
func (*Locker[T]) SetSubject ¶ added in v0.3.18
SetSubject adds a new subject to the locker.
Parameters:
- key: The key to add.
- subject: The subject to add.
- broadcast: A flag indicating whether the subject should broadcast or signal.
Behaviors:
- If the subject is nil, it will not be added.
- It overwrites the existing subject if the key already exists.
type Observer ¶ added in v0.3.18
type Observer[T any] interface { // Notify notifies the observer of a change. // // Parameters: // - change: The change that occurred. Notify(change T) }
Observer is the interface that wraps the Notify method.
type ReactiveObserver ¶ added in v0.3.18
type ReactiveObserver[T any] struct { // contains filtered or unexported fields }
ReactiveObserver is a type that acts as a simple observer that calls a function when a change occurs.
func NewReactiveObserver ¶ added in v0.3.18
func NewReactiveObserver[T any](event func(T)) *ReactiveObserver[T]
NewReactiveObserver creates a new ReactiveObserver.
Parameters:
- event: The event to call when a change occurs.
Returns:
- *ReactiveObserver[T]: A new ReactiveObserver.
func (*ReactiveObserver[T]) Notify ¶ added in v0.3.18
func (r *ReactiveObserver[T]) Notify(change T)
Notify implements the Observer interface.
type SafeMap ¶ added in v0.3.17
type SafeMap[T comparable, U any] struct { // contains filtered or unexported fields }
SafeMap is a thread-safe map.
func NewSafeMap ¶ added in v0.3.17
func NewSafeMap[T comparable, U any]() *SafeMap[T, U]
NewSafeMap creates a new SafeMap.
Returns:
- *SafeMap[T, U]: A new SafeMap.
func (*SafeMap[T, U]) Clear ¶ added in v0.3.17
func (sm *SafeMap[T, U]) Clear()
Clear removes all elements from the map.
func (*SafeMap[T, U]) Delete ¶ added in v0.3.17
func (sm *SafeMap[T, U]) Delete(key T)
Delete removes a key from the map.
Parameters:
- key: The key to remove.
func (*SafeMap[T, U]) Get ¶ added in v0.3.17
Get retrieves a value from the map.
Parameters:
- key: The key to retrieve the value.
Returns:
- U: The value associated with the key.
- bool: A boolean indicating if the key exists in the map.
func (*SafeMap[T, U]) GetMap ¶ added in v0.3.19
func (sm *SafeMap[T, U]) GetMap() map[T]U
GetMap returns the underlying map.
Returns:
- map[T]U: The underlying map.
func (*SafeMap[T, U]) Len ¶ added in v0.3.17
Len returns the number of elements in the map.
Returns:
- int: The number of elements in the map.
type ScanFunc ¶ added in v0.3.17
ScanFunc is a function that can be applied to all elements in the map.
Parameters:
- key: The key of the element.
- value: The value of the element.
Returns:
- bool: A boolean indicating if the scan should continue.
- error: An error if the scan should stop.
type Subject ¶ added in v0.3.18
type Subject[T any] struct { // contains filtered or unexported fields }
Subject is the subject that observers observe.
func NewSubject ¶ added in v0.3.18
NewSubject creates a new subject.
Parameters:
- state: The initial state of the subject.
Returns:
*Subject[T]: A new subject.
func (*Subject[T]) Attach ¶ added in v0.3.18
Attach attaches an observer to the subject.
Parameters:
- o: The observer to attach.
func (*Subject[T]) Copy ¶ added in v0.3.18
Copy implements the Copier interface.
However, the obsevers are not copied.
func (*Subject[T]) DoRead ¶ added in v0.3.18
func (s *Subject[T]) DoRead(f func(T))
DoRead is a method of the Subject type. It is used to perform a read operation on the value stored in the Subject. Through the function parameter, the caller can access the value in a read-only manner.
Parameters:
- f: A function that takes a value of type T as a parameter and returns nothing.
func (*Subject[T]) Get ¶ added in v0.3.18
func (s *Subject[T]) Get() T
Get gets the state of the subject.
Returns:
- T: The state of the subject.
func (*Subject[T]) ModifyState ¶ added in v0.3.18
func (s *Subject[T]) ModifyState(f func(T) T)
ModifyState modifies the state of the subject.
Parameters:
- f: The function to modify the state of the subject.
func (*Subject[T]) NotifyAll ¶ added in v0.3.18
func (s *Subject[T]) NotifyAll()
NotifyAll notifies all observers of a change.
func (*Subject[T]) Set ¶ added in v0.3.18
func (s *Subject[T]) Set(state T)
Set sets the state of the subject.
Parameters:
- state: The new state of the subject.
func (*Subject[T]) SetObserver ¶ added in v0.3.18
func (s *Subject[T]) SetObserver(action func(T))
SetObserver sets the observer of the subject.
Parameters:
- action: The action to set as the observer.