mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-06 05:30:08 +00:00
add wait many change for watcher
This commit is contained in:
12
conf/conf.go
12
conf/conf.go
@@ -8,6 +8,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Conf struct {
|
||||
@@ -63,10 +64,19 @@ func (p *Conf) Watch(filePath string, reload func()) error {
|
||||
return fmt.Errorf("new watcher error: %s", err)
|
||||
}
|
||||
go func() {
|
||||
var pre time.Time
|
||||
defer watcher.Close()
|
||||
for {
|
||||
select {
|
||||
case <-watcher.Events:
|
||||
case e := <-watcher.Events:
|
||||
if e.Has(fsnotify.Chmod) {
|
||||
continue
|
||||
}
|
||||
if pre.Add(1 * time.Second).After(time.Now()) {
|
||||
continue
|
||||
}
|
||||
time.Sleep(2 * time.Second)
|
||||
pre = time.Now()
|
||||
log.Println("config dir changed, reloading...")
|
||||
*p = *New()
|
||||
err := p.LoadFromPath(filePath)
|
||||
|
||||
Reference in New Issue
Block a user