Documentation
¶
Index ¶
- type Computed
- func (c *Computed[V]) Read() V
- func (c *Computed[V]) Run(ctx context.Context) error
- func (c *Computed[V]) Subscribe(ctx context.Context) <-chan V
- func (c *Computed[V]) Watch(ctx context.Context) <-chan struct{}
- func (c *Computed[V]) WithCoalesceWindow(window time.Duration) *Computed[V]
- func (c *Computed[V]) WithEqual(eq func(a, b V) bool) *Computed[V]
- func (c *Computed[V]) WithInitialNotify(enabled bool) *Computed[V]
- func (c *Computed[V]) WithSubscriberBuffer(buffer int) *Computed[V]
- type Debounce
- func (d *Debounce[V]) Read() V
- func (d *Debounce[V]) Run(ctx context.Context) error
- func (d *Debounce[V]) Subscribe(ctx context.Context) <-chan V
- func (d *Debounce[V]) Watch(ctx context.Context) <-chan struct{}
- func (d *Debounce[V]) WithInitialNotify(enabled bool) *Debounce[V]
- func (d *Debounce[V]) WithMaxWait(maxWait time.Duration) *Debounce[V]
- func (d *Debounce[V]) WithSubscriberBuffer(buffer int) *Debounce[V]
- type Link
- type Provider
- type Reader
- 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]) Watch(ctx context.Context) <-chan struct{}
- func (s *Signal[V]) WithEqual(eq func(a, b V) bool) *Signal[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]) WithSubscriberBuffer(buffer int) *Signal[V]
- type Subscriber
- type Throttle
- func (t *Throttle[V]) Read() V
- func (t *Throttle[V]) Run(ctx context.Context) error
- func (t *Throttle[V]) Subscribe(ctx context.Context) <-chan V
- func (t *Throttle[V]) Watch(ctx context.Context) <-chan struct{}
- func (t *Throttle[V]) WithInitialNotify(enabled bool) *Throttle[V]
- func (t *Throttle[V]) WithSubscriberBuffer(buffer int) *Throttle[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]) Watch(ctx context.Context) <-chan struct{}
- func (t *Trigger[V]) WithInitialNotify(enabled bool) *Trigger[V]
- func (t *Trigger[V]) WithInitialValue(initial V) *Trigger[V]
- func (t *Trigger[V]) WithSubscriberBuffer(buffer int) *Trigger[V]
- func (t *Trigger[V]) Write(ctx context.Context, value V) error
- type ViewFunc
- type Watcher
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Computed ¶ added in v0.0.32
Computed is a reactive value that updates itself based on its dependencies. It implements both Subscribable and Notifyable interfaces.
func NewComputed ¶ added in v0.0.32
NewComputed creates a new Computed with the given name, update function, and dependencies. The update function is called whenever any of the dependencies notify a change, and the result is broadcast to subscribers.
func (*Computed[V]) Read ¶ added in v0.0.32
func (c *Computed[V]) Read() V
Read returns the current value of the Computed. It acquires a read lock to ensure thread-safe access to the value.
func (*Computed[V]) Run ¶ added in v0.0.32
Run is the main loop for the Computed actor. It subscribes to all dependencies and listens for notifications. Whenever any dependency notifies a change, it calls the update function to compute the new value, updates its internal state, and broadcasts the new value to subscribers. The loop continues until the context is canceled, at which point it cleans up and exits.
func (*Computed[V]) Subscribe ¶ added in v0.0.32
Subscribe returns a channel that receives updates whenever the Computed's value changes. It subscribes to all dependencies and triggers an update whenever any of them notify a change. The current value is sent to the channel immediately upon subscription.
func (*Computed[V]) Watch ¶ added in v0.0.32
Watch returns a channel that receives notifications whenever any of the dependencies of the Computed change. It subscribes to all dependencies and triggers an update whenever any of them notify a change. The channel will receive a notification immediately upon subscription.
func (*Computed[V]) WithCoalesceWindow ¶ added in v0.0.32
WithCoalesceWindow configures the delay used to batch concurrent dependency updates. Defaults to 5ms, which is typically enough to catch immediately adjacent graph updates.
func (*Computed[V]) WithEqual ¶ added in v0.0.32
WithEqual configures a custom equality function to determine if the computed value has changed. If not set, the Computed will use the default equality check (==) to compare old and new values. This can be useful for complex types where a simple equality check may not be sufficient.
func (*Computed[V]) WithInitialNotify ¶ added in v0.0.32
WithInitialNotify configures whether new subscribers should receive the current value immediately upon subscribing.
func (*Computed[V]) WithSubscriberBuffer ¶ added in v0.0.32
WithSubscriberBuffer configures the buffer size for subscriber channels.
type Debounce ¶ added in v0.0.32
Debounce is a reactive value that delays broadcasting updates from its source until the source has stopped changing for a specified wait duration.
func NewDebounce ¶ added in v0.0.32
NewDebounce creates a new Debounce actor attached to a source provider.
func (*Debounce[V]) Read ¶ added in v0.0.32
func (d *Debounce[V]) Read() V
Read returns the currently settled value safely.
func (*Debounce[V]) Run ¶ added in v0.0.32
Run is the main actor loop. It subscribes to the source and manages the sliding window.
func (*Debounce[V]) Subscribe ¶ added in v0.0.32
Subscribe returns a channel that receives the debounced updates.
func (*Debounce[V]) Watch ¶ added in v0.0.32
Watch returns a channel that receives notifications when the value settles.
func (*Debounce[V]) WithInitialNotify ¶ added in v0.0.32
WithInitialNotify configures whether new subscribers receive the current value immediately.
func (*Debounce[V]) WithMaxWait ¶ added in v0.0.32
WithMaxWait configures a maximum time to wait before forcing an update, preventing infinite starvation if the source is constantly changing.
func (*Debounce[V]) WithSubscriberBuffer ¶ added in v0.0.32
WithSubscriberBuffer configures the buffer size for subscriber channels.
type Link ¶ added in v0.0.32
Link is a supervised actor that subscribes to a Provider and writes every value it receives to a Writer. It eliminates the need for manual, unsupervised goroutines when connecting reactive pipelines.
type Provider ¶ added in v0.0.32
Provider represents any reactive actor that emits values. Trigger, Signal, Derived, and Debounce all satisfy this interface.
type Reader ¶ added in v0.0.29
type Reader[V any] interface { Read() V }
Reader 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. It acquires a read lock to ensure thread-safe access to the value.
func (*Signal[V]) Run ¶
Run starts the Signal's update loop, which periodically calls the update function to refresh the Signal's value and notifies subscribers of any changes. The loop continues until the provided context is canceled, at which point it will clean up all subscriber channels.
func (*Signal[V]) Subscribe ¶
Subscribe allows clients to subscribe to updates of the Signal's value. It returns a channel that will receive new values whenever they are updated. The subscription will automatically clean up when the provided context is canceled.
func (*Signal[V]) Watch ¶ added in v0.0.29
Watch allows clients to subscribe to notifications whenever the Signal's value is updated, without receiving the actual value. It returns a channel that will receive a notification (empty struct) whenever the value is updated. The subscription will automatically clean up when the provided context is canceled.
func (*Signal[V]) WithEqual ¶ added in v0.0.32
WithEqual configures a custom equality function to determine if the Signal's value has changed. If not set, the Signal will use the default equality check (==) to compare old and new values. This can be useful for complex types where a simple equality check may not be sufficient.
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]) WithSubscriberBuffer ¶
WithSubscriberBuffer configures the buffer size for subscriber channels to prevent blocking on updates.
type Subscriber ¶ added in v0.0.29
Subscriber represents a value that can be subscribed to for updates. The Subscribe method returns a channel that will receive the updated value whenever it changes. The channel will be closed when the context is canceled.
type Throttle ¶ added in v0.0.32
Throttle is a reactive value that limits the rate at which updates from its source are broadcast. It ensures that updates are sent at most once per interval, always emitting the most recent (trailing) value from that interval.
func NewThrottle ¶ added in v0.0.32
NewThrottle creates a new Throttle actor attached to a source provider.
func (*Throttle[V]) Read ¶ added in v0.0.32
func (t *Throttle[V]) Read() V
Read returns the currently settled value safely.
func (*Throttle[V]) Run ¶ added in v0.0.32
Run is the main actor loop. It manages the trailing-edge rate limit.
func (*Throttle[V]) Subscribe ¶ added in v0.0.32
Subscribe returns a channel that receives the throttled updates.
func (*Throttle[V]) Watch ¶ added in v0.0.32
Watch returns a channel that receives notifications when the value updates.
func (*Throttle[V]) WithInitialNotify ¶ added in v0.0.32
WithInitialNotify configures whether new subscribers receive the current value immediately.
func (*Throttle[V]) WithSubscriberBuffer ¶ added in v0.0.32
WithSubscriberBuffer configures the buffer size for subscriber channels.
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 returns the current value of the Trigger. It acquires a lock to ensure thread-safe access to the value.
func (*Trigger[V]) Run ¶ added in v0.0.17
Run starts the Trigger's main loop, which waits for the context to be canceled. When the context is canceled, it cleans up all subscriber channels. This method should be run in a separate goroutine.
func (*Trigger[V]) Subscribe ¶ added in v0.0.17
Subscribe returns a channel that receives updates whenever the Trigger's value changes. If initialNotify is enabled, the current value is sent to the channel immediately upon subscription. It acquires a lock to ensure thread-safe access to the current value when subscribing.
func (*Trigger[V]) Watch ¶ added in v0.0.29
Watch allows clients to subscribe to notifications whenever the Trigger's value is updated, without receiving the actual value. It returns a channel that will receive a notification (empty struct) whenever the value is updated. The subscription will automatically clean up when the provided context is canceled.
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]) WithSubscriberBuffer ¶ added in v0.0.17
WithSubscriberBuffer configures the buffer size for subscriber channels to prevent blocking on updates.
type ViewFunc ¶ added in v0.0.32
type ViewFunc[V any] func() V
ViewFunc is an adapter to allow the use of ordinary functions as Readers. If f is a function with the appropriate signature, ViewFunc(f) is a Reader that calls f.