watch

package
Version: v0.0.0-...-9649366 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package watch provides utilities for watching resources for changes.

Index

Constants

This section is empty.

Variables

View Source
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

type GetUpdateFn func(updatable Updatable) (interface{}, error)

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

type NewUpdatableFn func() (Updatable, error)

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
}

Options provide a set of value options.

func NewOptions

func NewOptions() Options

NewOptions creates a new set of options.

type ProcessFn

type ProcessFn func(update interface{}) error

ProcessFn processes an update.

type Source

type Source interface {
	close.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.

func NewSource

func NewSource(input SourceInput, logger *zap.Logger) Source

NewSource returns a new Source.

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 {
	xclose.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.

func NewValue

func NewValue(
	opts Options,
) Value

NewValue creates a new value.

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 {
	xclose.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

func NewWatchable

func NewWatchable() Watchable

NewWatchable returns a Watchable

Jump to

Keyboard shortcuts

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