Documentation
¶
Index ¶
- type Mirror
- type Readable
- type Signal
- func (s *Signal[V]) Read() V
- func (s *Signal[V]) Run(ctx context.Context) error
- func (s *Signal[V]) Subscribe(ctx context.Context) <-chan V
- func (s *Signal[V]) WithInitialNotify(enabled bool) *Signal[V]
- func (s *Signal[V]) WithInitialValue(initial V) *Signal[V]
- func (s *Signal[V]) WithInterval(interval time.Duration) *Signal[V]
- func (s *Signal[V]) WithMailboxSize(size int) *Signal[V]
- func (s *Signal[V]) WithSubscriberBuffer(buffer int) *Signal[V]
- type Trigger
- func (t *Trigger[V]) Read() V
- func (t *Trigger[V]) Run(ctx context.Context) error
- func (t *Trigger[V]) Subscribe(ctx context.Context) <-chan V
- func (t *Trigger[V]) Sync() error
- func (t *Trigger[V]) WithInitialNotify(enabled bool) *Trigger[V]
- func (t *Trigger[V]) WithInitialValue(initial V) *Trigger[V]
- func (t *Trigger[V]) WithMailboxSize(size int) *Trigger[V]
- func (t *Trigger[V]) WithSubscriberBuffer(buffer int) *Trigger[V]
- func (t *Trigger[V]) Write(value V) error
- type Writable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Mirror ¶ added in v0.0.19
type Mirror[V any] struct { // contains filtered or unexported fields }
Mirror is a simple implementation of Readable that returns the value from a provided function. It does not have any internal state and always reflects the current value from the function.
type Readable ¶ added in v0.0.19
type Readable[V any] interface { Read() V }
Readable represents a value that can be read. The Read method returns the current value.
type Signal ¶
Signal represents a value that is periodically updated by a function and can be subscribed to for updates.
func (*Signal[V]) Read ¶ added in v0.0.18
func (s *Signal[V]) Read() V
Read returns the current value of the Signal by sending a call message to its mailbox.
func (*Signal[V]) Run ¶
Run starts the main loop of the Signal, which periodically updates its value by calling the provided function and notifies subscribers of changes. It also handles incoming messages for getting the current value and managing subscriptions.
func (*Signal[V]) Subscribe ¶
Subscribe allows clients to receive updates whenever the Signal's value changes. It returns a channel that will receive new values.
func (*Signal[V]) WithInitialNotify ¶
WithInitialNotify configures whether new subscribers should receive the current value immediately upon subscribing.
func (*Signal[V]) WithInitialValue ¶
WithInitialValue sets the initial value of the Signal before any updates occur.
func (*Signal[V]) WithInterval ¶
WithInterval sets the interval at which the Signal's update function is called to refresh its value.
func (*Signal[V]) WithMailboxSize ¶
WithMailboxSize allows configuring the mailbox buffer size for the Signal.
func (*Signal[V]) WithSubscriberBuffer ¶
WithSubscriberBuffer configures the buffer size for subscriber channels to prevent blocking on updates.
type Trigger ¶ added in v0.0.17
Trigger represents a value that can be updated by a function and subscribed to for updates.
func NewTrigger ¶ added in v0.0.17
NewTrigger creates a new Trigger with the given name and update function.
func (*Trigger[V]) Read ¶ added in v0.0.18
func (t *Trigger[V]) Read() V
Read retrieves the current value of the Trigger.
func (*Trigger[V]) Run ¶ added in v0.0.17
Run starts the Trigger's main loop, processing incoming messages. It should be run in a separate goroutine and will continue until the context is canceled or the mailbox is closed.
func (*Trigger[V]) Subscribe ¶ added in v0.0.17
Subscribe returns a channel that receives updates whenever the Trigger's value changes. The subscription is automatically cleaned up when the context is done.
func (*Trigger[V]) Sync ¶ added in v0.0.17
Sync forces the Trigger to re-evaluate its current value by calling the update function with the current value. This can be used to trigger updates to subscribers even if the value hasn't changed.
func (*Trigger[V]) WithInitialNotify ¶ added in v0.0.17
WithInitialNotify configures whether new subscribers should receive the current value immediately upon subscribing.
func (*Trigger[V]) WithInitialValue ¶ added in v0.0.17
WithInitialValue sets the initial value of the Trigger before any updates occur.
func (*Trigger[V]) WithMailboxSize ¶ added in v0.0.17
WithMailboxSize allows configuring the mailbox buffer size for the Trigger.
func (*Trigger[V]) WithSubscriberBuffer ¶ added in v0.0.17
WithSubscriberBuffer configures the buffer size for subscriber channels to prevent blocking on updates.