1 // +build darwin,!ios freebsd linux,!arm64 netbsd solaris windows
6 //"github.com/rjeczalik/notify"
13 //ev chan notify.EventInfo
17 func newWatcher(kc *keyCache) *watcher {
20 //ev: make(chan notify.EventInfo, 10),
21 quit: make(chan struct{}),
25 // starts the watcher loop in the background.
26 // Start a watcher in the background if that's not already in progress.
27 // The caller must hold w.kc.mu.
28 func (w *watcher) start() {
29 if w.starting || w.running {
36 func (w *watcher) close() {
40 func (w *watcher) loop() {
49 err := notify.Watch(w.kc.keydir, w.ev, notify.All)
51 fmt.Printf("can't watch %s: %v", w.kc.keydir, err)
54 defer notify.Stop(w.ev)
55 fmt.Printf("now watching %s", w.kc.keydir)
56 defer fmt.Printf("no longer watching %s", w.kc.keydir)
62 // Wait for file system events and reload.
63 // When an event occurs, the reload call is delayed a bit so that
64 // multiple events arriving quickly only cause a single reload.
66 debounce = time.NewTimer(0)
67 debounceDuration = 500 * time.Millisecond
68 inCycle, hadEvent bool
77 debounce.Reset(debounceDuration)
87 debounce.Reset(debounceDuration)
88 inCycle, hadEvent = true, false
90 inCycle, hadEvent = false, false