1 // Copyright 2016 The go-ethereum Authors
2 // This file is part of the go-ethereum library.
4 // The go-ethereum library is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // The go-ethereum library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public License
15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
17 // +build darwin,!ios freebsd linux,!arm64 netbsd solaris windows
24 "github.com/rjeczalik/notify"
31 ev chan notify.EventInfo
35 func newWatcher(ac *addrCache) *watcher {
38 ev: make(chan notify.EventInfo, 10),
39 quit: make(chan struct{}),
43 // starts the watcher loop in the background.
44 // Start a watcher in the background if that's not already in progress.
45 // The caller must hold w.ac.mu.
46 func (w *watcher) start() {
47 if w.starting || w.running {
54 func (w *watcher) close() {
58 func (w *watcher) loop() {
66 err := notify.Watch(w.ac.keydir, w.ev, notify.All)
68 fmt.Printf("can't watch %s: %v", w.ac.keydir, err)
71 defer notify.Stop(w.ev)
72 fmt.Printf("now watching %s", w.ac.keydir)
73 defer fmt.Printf("no longer watching %s", w.ac.keydir)
79 // Wait for file system events and reload.
80 // When an event occurs, the reload call is delayed a bit so that
81 // multiple events arriving quickly only cause a single reload.
83 debounce = time.NewTimer(0)
84 debounceDuration = 500 * time.Millisecond
85 inCycle, hadEvent bool
94 debounce.Reset(debounceDuration)
104 debounce.Reset(debounceDuration)
105 inCycle, hadEvent = true, false
107 inCycle, hadEvent = false, false