refreshable

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: BSD-3-Clause Imports: 7 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToV2 added in v1.5.0

ToV2 converts from a v1 Refreshable created by this package to v2 supporting type safety via generics. If v1's value is not of type T, the function panics.

Types

type Bool

type Bool interface {
	Refreshable
	CurrentBool() bool
	MapBool(func(bool) interface{}) Refreshable
	SubscribeToBool(func(bool)) (unsubscribe func())
}

func NewBool

func NewBool(in Refreshable) Bool

type BoolPtr

type BoolPtr interface {
	Refreshable
	CurrentBoolPtr() *bool
	MapBoolPtr(func(*bool) interface{}) Refreshable
	SubscribeToBoolPtr(func(*bool)) (unsubscribe func())
}

func NewBoolPtr

func NewBoolPtr(in Refreshable) BoolPtr

type DefaultRefreshable

type DefaultRefreshable struct {
	sync.Mutex // protects subscribers
	// contains filtered or unexported fields
}

func NewDefaultRefreshable

func NewDefaultRefreshable(val interface{}) *DefaultRefreshable

func (*DefaultRefreshable) Current

func (d *DefaultRefreshable) Current() interface{}

func (*DefaultRefreshable) Map

func (d *DefaultRefreshable) Map(mapFn func(interface{}) interface{}) Refreshable

func (*DefaultRefreshable) Subscribe

func (d *DefaultRefreshable) Subscribe(consumer func(interface{})) (unsubscribe func())

func (*DefaultRefreshable) Update

func (d *DefaultRefreshable) Update(val interface{}) error

type Duration

type Duration interface {
	Refreshable
	CurrentDuration() time.Duration
	MapDuration(func(time.Duration) interface{}) Refreshable
	SubscribeToDuration(func(time.Duration)) (unsubscribe func())
}

Duration is a Refreshable that can return the current time.Duration.

func NewDuration

func NewDuration(in Refreshable) Duration

type DurationPtr

type DurationPtr interface {
	Refreshable
	CurrentDurationPtr() *time.Duration
	MapDurationPtr(func(*time.Duration) interface{}) Refreshable
	SubscribeToDurationPtr(func(*time.Duration)) (unsubscribe func())
}

func NewDurationPtr

func NewDurationPtr(in Refreshable) DurationPtr

type Float64 added in v1.2.0

type Float64 interface {
	Refreshable
	CurrentFloat64() float64
	MapFloat64(func(float64) interface{}) Refreshable
	SubscribeToFloat64(func(float64)) (unsubscribe func())
}

func NewFloat64 added in v1.2.0

func NewFloat64(in Refreshable) Float64

type Float64Ptr added in v1.2.0

type Float64Ptr interface {
	Refreshable
	CurrentFloat64Ptr() *float64
	MapFloat64Ptr(func(*float64) interface{}) Refreshable
	SubscribeToFloat64Ptr(func(*float64)) (unsubscribe func())
}

func NewFloat64Ptr added in v1.2.0

func NewFloat64Ptr(in Refreshable) Float64Ptr

type Int

type Int interface {
	Refreshable
	CurrentInt() int
	MapInt(func(int) interface{}) Refreshable
	SubscribeToInt(func(int)) (unsubscribe func())
}

func NewInt

func NewInt(in Refreshable) Int

type Int64 added in v1.2.0

type Int64 interface {
	Refreshable
	CurrentInt64() int64
	MapInt64(func(int64) interface{}) Refreshable
	SubscribeToInt64(func(int64)) (unsubscribe func())
}

func NewInt64 added in v1.2.0

func NewInt64(in Refreshable) Int64

type Int64Ptr added in v1.2.0

type Int64Ptr interface {
	Refreshable
	CurrentInt64Ptr() *int64
	MapInt64Ptr(func(*int64) interface{}) Refreshable
	SubscribeToInt64Ptr(func(*int64)) (unsubscribe func())
}

func NewInt64Ptr added in v1.2.0

func NewInt64Ptr(in Refreshable) Int64Ptr

type IntPtr

type IntPtr interface {
	Refreshable
	CurrentIntPtr() *int
	MapIntPtr(func(*int) interface{}) Refreshable
	SubscribeToIntPtr(func(*int)) (unsubscribe func())
}

func NewIntPtr

func NewIntPtr(in Refreshable) IntPtr

type Refreshable

type Refreshable interface {
	// Current returns the most recent value of this Refreshable.
	Current() interface{}

	// Subscribe subscribes to changes of this Refreshable. The provided function is called with the value of Current()
	// whenever the value changes.
	Subscribe(consumer func(interface{})) (unsubscribe func())

	// Map returns a new Refreshable based on the current one that handles updates based on the current Refreshable.
	Map(func(interface{}) interface{}) Refreshable
}

func FromV2 added in v1.5.0

func FromV2[T any](v2 refreshablev2.Refreshable[T]) Refreshable

FromV2 converts from a v1 Refreshable created by this package to v2 supporting type safety via generics.

type String

type String interface {
	Refreshable
	CurrentString() string
	MapString(func(string) interface{}) Refreshable
	SubscribeToString(func(string)) (unsubscribe func())
}

func NewString

func NewString(in Refreshable) String

type StringPtr

type StringPtr interface {
	Refreshable
	CurrentStringPtr() *string
	MapStringPtr(func(*string) interface{}) Refreshable
	SubscribeToStringPtr(func(*string)) (unsubscribe func())
}

func NewStringPtr

func NewStringPtr(in Refreshable) StringPtr

type StringSlice

type StringSlice interface {
	Refreshable
	CurrentStringSlice() []string
	MapStringSlice(func([]string) interface{}) Refreshable
	SubscribeToStringSlice(func([]string)) (unsubscribe func())
}

func NewStringSlice

func NewStringSlice(in Refreshable) StringSlice

type ValidatingRefreshable

type ValidatingRefreshable struct {
	Refreshable
	// contains filtered or unexported fields
}

func NewMapValidatingRefreshable added in v1.3.0

func NewMapValidatingRefreshable(origRefreshable Refreshable, mappingFn func(interface{}) (interface{}, error)) (*ValidatingRefreshable, error)

NewMapValidatingRefreshable is similar to NewValidatingRefreshable but allows for the function to return a mapping/mutation of the input object in addition to returning an error. The returned ValidatingRefreshable will contain the mapped value. The mapped value must always be of the same type (but not necessarily that of the input type).

func NewValidatingRefreshable

func NewValidatingRefreshable(origRefreshable Refreshable, validatingFn func(interface{}) error) (*ValidatingRefreshable, error)

NewValidatingRefreshable returns a new Refreshable whose current value is the latest value that passes the provided validatingFn successfully. This returns an error if the current value of the passed in Refreshable does not pass the validatingFn or if the validatingFn or Refreshable are nil.

func (*ValidatingRefreshable) LastValidateErr

func (v *ValidatingRefreshable) LastValidateErr() error

Jump to

Keyboard shortcuts

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