driver

package
v0.0.0-...-2bcf714 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package driver provides the interface for providers of runtimevar. This serves as a contract of how the runtimevar API uses a provider implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Variable

type Variable struct {
	Value      interface{}
	UpdateTime time.Time
}

Variable contains a runtime variable and additional metadata about it.

type Watcher

type Watcher interface {
	// WatchVariable blocks until the variable changes, the Context's Done channel closes or an
	// error occurs.
	//
	// If the variable has changed, then WatchVariable must return a Variable object with the
	// new value.
	//
	// Implementations should also avoid returning the same error repeatedly. In particular,
	// when the variable is deleted, WatchVariable must return an error upon initial detection,
	// but succeeding WatchVariable calls must block until the variable is restored, and not
	// repeatedly return errors.
	//
	// To stop this function from blocking, caller can passed in Context object constructed via
	// WithCancel and call the cancel function.
	WatchVariable(context.Context) (Variable, error)
	// Close cleans up any resources used by the Watcher object.
	Close() error
}

Watcher watches for updates on a variable and returns an updated Variable object if there are changes. A Watcher object is associated with a variable upon construction.

An application can have more than one Watcher, one for each variable. It is typical to only have one Watcher per variable.

A Watcher provider can dictate the type of Variable.Value if the backend service dictates a particular format and type. If the backend service has the flexibility to store bytes and allow clients to dictate the format, it is better for a Watcher provider to allow users to dictate the type of Variable.Value and a decoding function. The Watcher provider can use the runtimevar.Decoder to facilitate the decoding logic.

Jump to

Keyboard shortcuts

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