# README
Poll Watcher
Poll Watcher is a konfig.Watcher that sends events every x time given in the konfig.
Usage
import (
"fmt"
"os"
"time"
"github.com/lalamove/konfig"
"github.com/lalamove/konfig/loader/klenv"
"github.com/lalamove/konfig/watcher/kwpoll"
)
func main() {
os.Setenv("foo", "bar")
var l = klenv.New(&klenv.Config{
Vars: []string{
"foo",
},
})
var v = konfig.Values{}
l.Load(v)
var w = kwpoll.New(&kwpoll.Config{
Rater: kwpoll.Time(100 * time.Millisecond),
Loader: l,
Diff: true,
Debug: true,
InitValue: v,
})
w.Start()
var timer = time.NewTimer(200 * time.Millisecond)
var watched int
os.Setenv("foo", "baz") // change the value
main:
for {
select {
case <-timer.C:
w.Close()
break main
case <-w.Watch():
watched++
}
}
fmt.Println(watched) // will output 1
}
# Functions
New creates a new PollWatcher fromt the given config.
# Variables
ErrAlreadyClosed is the error returned when trying to close an already closed PollDiffWatcher.
ErrNoLoader is the error returned when no Loader is set and Diff is set to true.
ErrNoWatcherSupplied is the error returned when Watch in general config is false but a watcher is still being registered.
# Structs
Config is the config of a PollWatcher.
PollWatcher is a konfig.Watcher that sends events every x time given in the konfig.
# Interfaces
Rater is an interface that exposes a single Time method which returns the time until the next tick.
# Type aliases
Time is a time.Duration which implements the Rater interface.