Documentation
¶
Overview ¶
Package utils provides small shared helpers for common value handling.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Default ¶
func Default[T comparable](value, fallback T) T
Default returns fallback when value is the zero value for T.
func DefaultString ¶
DefaultString returns fallback when value is empty.
Types ¶
type DebouncedHandler ¶
DebouncedHandler handles the final value that survives a debounce window.
type ErrorHandler ¶
ErrorHandler observes handler errors without coupling callers to background execution.
type MergeFunc ¶
type MergeFunc[T any] func(existing T, incoming T) T
MergeFunc merges an incoming value into the existing pending value. Return the merged result. If nil, the incoming value replaces the existing one.
type TrailingDebouncer ¶
type TrailingDebouncer[T any] struct { // contains filtered or unexported fields }
TrailingDebouncer keeps the latest call for each key and runs it after the window is quiet.
func NewTrailingDebouncer ¶
func NewTrailingDebouncer[T any](window time.Duration, handler DebouncedHandler[T], onError ErrorHandler, merge MergeFunc[T]) (*TrailingDebouncer[T], error)
NewTrailingDebouncer creates a keyed trailing-edge debouncer. If merge is nil, Call replaces the pending value; otherwise it merges via merge(existing, incoming).