Documentation ¶
Overview ¶
Package stopvar contains helpers that build on both the stopper and notify packages.
Index ¶
- func DoWhenChanged[T comparable](ctx *stopper.Context, start T, source *notify.Var[T], ...) (last T, err error)
- func DoWhenChangedOrInterval[T comparable](ctx *stopper.Context, start T, source *notify.Var[T], period time.Duration, ...) (last T, err error)
- func WaitForChange[T comparable](ctx *stopper.Context, current T, source *notify.Var[T]) (next T, changed <-chan struct{})
- func WaitForChangeOrDuration[T comparable](ctx *stopper.Context, current T, source *notify.Var[T], d time.Duration) (next T, changed <-chan struct{})
- func WaitForValue[T comparable](ctx *stopper.Context, expected T, source *notify.Var[T]) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoWhenChanged ¶
func DoWhenChanged[T comparable]( ctx *stopper.Context, start T, source *notify.Var[T], fn func(ctx *stopper.Context, old, new T) error, ) (last T, err error)
DoWhenChanged executes the callback when the variable has changed to a different value. That is, if the variable is set to existing value, the callback will not be be invoked. If an error is returned from the callback, the last successfully-processed value will be returned.
func DoWhenChangedOrInterval ¶
func DoWhenChangedOrInterval[T comparable]( ctx *stopper.Context, start T, source *notify.Var[T], period time.Duration, fn func(ctx *stopper.Context, old, new T) error, ) (last T, err error)
DoWhenChangedOrInterval executes the callback when the variable has changed or if the configured period of time has elapsed since the last invocation. This is useful when some activity should be taken in response to a change or at a somewhat regular interval. If an error is returned from the callback, the last successfully-processed value will be returned.
func WaitForChange ¶
func WaitForChange[T comparable]( ctx *stopper.Context, current T, source *notify.Var[T], ) (next T, changed <-chan struct{})
WaitForChange is a utility function that waits for the source to change to another value. If the context is stopped, the most recent value will be returned.
func WaitForChangeOrDuration ¶
func WaitForChangeOrDuration[T comparable]( ctx *stopper.Context, current T, source *notify.Var[T], d time.Duration, ) (next T, changed <-chan struct{})
WaitForChangeOrDuration is a utility function that waits for the source to change to another value or for the given duration to elapse.
func WaitForValue ¶
WaitForValue is a utility function that waits until the source emits the requested value. This is primarily intended for testing.
Types ¶
This section is empty.