Skip to content

Commit 7299ff9

Browse files
committed
fix(daemon): avoid process before file saves done.
1 parent 8236f3d commit 7299ff9

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

_example/clash.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ proxy-groups:
4444
url: http://www.gstatic.com/generate_204
4545
interval: 300
4646
timeout: 2000
47-
max-failed-times: 5
4847
lazy: true
4948
- name: main
5049
type: select

daemon/daemon.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,7 @@ func watch(watcher *fsnotify.Watcher) {
6262
lastEvent[f.Name] = now
6363
sLock.Unlock()
6464

65-
log.L().Sugar().Infof("File %s modified", f.Name)
66-
err := convert.Convert(convert.Task{
67-
Source: conf.Convert.Source,
68-
Target: conf.Convert.Target,
69-
File: f,
70-
})
71-
if err != nil {
72-
log.L().Sugar().Errorf("Convert %s error: %v", f.Name, err)
73-
}
74-
75-
refreshChan <- struct{}{}
65+
go updateFile(f)
7666
}
7767
}
7868
}
@@ -85,3 +75,19 @@ func watch(watcher *fsnotify.Watcher) {
8575
}
8676
}
8777
}
78+
79+
func updateFile(f conf.File) {
80+
time.Sleep(time.Second)
81+
82+
log.L().Sugar().Infof("File %s modified", f.Name)
83+
err := convert.Convert(convert.Task{
84+
Source: conf.Convert.Source,
85+
Target: conf.Convert.Target,
86+
File: f,
87+
})
88+
if err != nil {
89+
log.L().Sugar().Errorf("Convert %s error: %v", f.Name, err)
90+
}
91+
92+
refreshChan <- struct{}{}
93+
}

0 commit comments

Comments
 (0)