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