dynamic

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package dynamic implements values that change themselves over time in a specified way. A Float32 can be interpolated, or run a Profile, which is a time series of Segments.

Index

Constants

View Source
const DefaultUpdateInterval = 100 * time.Millisecond

Variables

Functions

This section is empty.

Types

type Completion

type Completion interface {
	// Done returns a channel which will be closed when the action completes.
	Done() <-chan struct{}
}

Completion provides a way to wait for an action to complete, by waiting on Done. Calls that start an action in the background can return an implementation of Completion to allow the caller to tell when the action is completed. Completion does not provide any way of conveying return or error values; use a different abstraction if these are required.

type Float32

type Float32 struct {
	// contains filtered or unexported fields
}

Float32 is a float32 that can change over time.

func NewFloat32

func NewFloat32(initial float32, options ...Float32Option) *Float32

func (*Float32) Get

func (f *Float32) Get() float32

Get retrieves the current value contained in this Float32.

func (*Float32) GetAndListen

func (f *Float32) GetAndListen() (float32, *broadcast.VariableListener)

func (*Float32) Listen

func (f *Float32) Listen() *broadcast.VariableListener

Listen returns a VariableListener that sends updates whenever the Float32 changes for any reason. The values in events will always be float32.

func (*Float32) Set

func (f *Float32) Set(value float32)

Set will change this Float32 to a constant level. Any interpolations or profiles currently running will be stopped.

func (*Float32) StartInterpolation

func (f *Float32) StartInterpolation(ctx context.Context, target float32, d time.Duration) Completion

StartInterpolation will begin a real-time linear interpolation of the Float32, from the current value to the target, taking place over the duration d. Only one interpolation may be in progress at a time. Any other interpolations or profiles that are in progress will be stopped, and the new interpolation run in their place. Cancel ctx to halt the interpolation - the Float32 will freeze as-is. The returned context (which inherits from the provided ctx) will be cancelled when the interpolation stops.

func (*Float32) StartProfile

func (f *Float32) StartProfile(ctx context.Context, profile profile.Profile, change time.Duration) Completion

StartProfile will simulate a profile on the Float32, starting at the current time. The Float32 will be interpolated to each dynamic.Segment level in turn. The interpolation time is specified by the parameter change. After all segments are done, the value will be interpolated to profile.FinalLevel Cancel ctx to stop the profile from running. The value will be frozen as-is. The returned context.Context (which inherits from ctx) will be cancelled once the profile has finished simulating and the Float32 has reached profile.FinalLevel

func (*Float32) Stop

func (f *Float32) Stop()

Stop will stop any interpolations or profiles that are currently running on this Float32.

type Float32Option

type Float32Option func(value *Float32)

func WithClock

func WithClock(clk clock.Clock) Float32Option

func WithLogger

func WithLogger(logger *zap.Logger) Float32Option

func WithUpdateInterval

func WithUpdateInterval(interval time.Duration) Float32Option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL