Help only fire config reload once per save.
This commit is contained in:
+16
-1
@@ -10,6 +10,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultPostfix = "_config.json"
|
const DefaultPostfix = "_config.json"
|
||||||
@@ -118,12 +119,26 @@ func NewWatchConfig(filepath string, decode DecodeConfig, defaultConfig interfac
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (wc *WatchConfig) run() {
|
func (wc *WatchConfig) run() {
|
||||||
|
// Work around watch events being sent more then once.
|
||||||
|
ticker := time.NewTicker(time.Second)
|
||||||
|
trigger := false
|
||||||
|
waitOnce := false
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-wc.close:
|
case <-wc.close:
|
||||||
return
|
return
|
||||||
case <-wc.watch.Event:
|
case <-wc.watch.Event:
|
||||||
wc.C <- wc
|
trigger = true
|
||||||
|
case <-ticker.C:
|
||||||
|
// Think of this as a PLC state machine.
|
||||||
|
if trigger && waitOnce {
|
||||||
|
wc.C <- wc
|
||||||
|
trigger = false
|
||||||
|
waitOnce = false
|
||||||
|
}
|
||||||
|
if trigger && !waitOnce {
|
||||||
|
waitOnce = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user