Documentation
¶
Overview ¶
Package watch provides utilities for watching resources for changes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrSourceClosed = errors.New("source closed")
ErrSourceClosed indicates that the Source should be closed.
Functions ¶
This section is empty.
Types ¶
type CreateWatchError ¶
type CreateWatchError struct {
// contains filtered or unexported fields
}
CreateWatchError is returned when encountering an error creating a watch.
func (CreateWatchError) Error ¶
func (e CreateWatchError) Error() string
type GetUpdateFn ¶
GetUpdateFn returns the latest value.
type InitValueError ¶
type InitValueError struct {
// contains filtered or unexported fields
}
InitValueError is returned when encountering an error when initializing a value.
func (InitValueError) Error ¶
func (e InitValueError) Error() string
type NewUpdatableFn ¶
NewUpdatableFn creates an updatable.
type Options ¶
type Options interface {
// SetInstrumentOptions sets the instrument options.
SetInstrumentOptions(value instrument.Options) Options
// InstrumentOptions returns the instrument options.
InstrumentOptions() instrument.Options
// SetInitWatchTimeout sets the initial watch timeout.
SetInitWatchTimeout(value time.Duration) Options
// InitWatchTimeout returns the initial watch timeout.
InitWatchTimeout() time.Duration
// SetNewUpdatableFn sets the new updatable function.
SetNewUpdatableFn(value NewUpdatableFn) Options
// NewUpdatableFn returns the new updatable function.
NewUpdatableFn() NewUpdatableFn
// SetGetUpdateFn sets the get function.
SetGetUpdateFn(value GetUpdateFn) Options
// GetUpdateFn returns the get function.
GetUpdateFn() GetUpdateFn
// SetProcessFn sets the process function.
SetProcessFn(value ProcessFn) Options
// ProcessFn returns the process function.
ProcessFn() ProcessFn
// Key returns the key for the watch.
Key() string
// SetKey sets the key for the watch.
SetKey(key string) Options
// InterruptedCh returns the interrupted channel.
InterruptedCh() <-chan struct{}
// SetInterruptedCh sets the interrupted channel.
SetInterruptedCh(value <-chan struct{}) Options
}
Options provide a set of value options.
type Source ¶
type Source interface {
xresource.SimpleCloser
// Get returns the latest value.
Get() interface{}
// Watch returns the value and a Watch.
Watch() (interface{}, Watch, error)
}
Source polls data by calling SourcePollFn and notifies its watches on updates.
type SourceInput ¶
type SourceInput interface {
// Poll will be called by Source for data. Any backoff/jitter logic should
// be handled here.
Poll() (interface{}, error)
}
SourceInput provides data for Source,
type Updatable ¶
type Updatable interface {
xresource.SimpleCloser
// C returns the notification channel for updates.
C() <-chan struct{}
}
Updatable can be updated.
type Value ¶
type Value interface {
// Watch starts watching for value updates.
Watch() error
// Unwatch stops watching for value updates.
Unwatch()
}
Value is a resource that can be updated during runtime.
type Watch ¶
type Watch interface {
Updatable
// Get returns the latest value of the Watchable instance.
Get() interface{}
}
Watch watches a Watchable instance, can get notification when the Watchable updates.
type Watchable ¶
type Watchable interface {
xresource.SimpleCloser
// IsClosed returns true if the Watchable is closed
IsClosed() bool
// Get returns the latest value
Get() interface{}
// Watch returns the value and a Watch that will be notified on updates
Watch() (interface{}, Watch, error)
// NumWatches returns the number of watches on the Watchable
NumWatches() int
// Update sets the value and notify Watches
Update(interface{}) error
}
Watchable can be watched