MCPcopy Create free account
hub / github.com/AudDMusic/RedditBot / WatchChanges

Function WatchChanges

main.go:1171–1197  ·  view source on GitHub ↗
(filename string, updated chan struct{}, l *rate.Limiter)

Source from the content-addressed store, hash-verified

1169}
1170
1171func WatchChanges(filename string, updated chan struct{}, l *rate.Limiter) {
1172 watcher, err := fsnotify.NewWatcher()
1173 capture(err)
1174 defer captureFunc(watcher.Close)
1175 done := make(chan bool)
1176 go func() {
1177 for {
1178 select {
1179 case event := <-watcher.Events:
1180 fmt.Println(event)
1181 if l != nil {
1182 if l.Allow() {
1183 updated <- struct{}{}
1184 } else {
1185 fmt.Println("skipping")
1186 }
1187 }
1188 case err := <-watcher.Errors:
1189 capture(err)
1190 }
1191 }
1192 }()
1193 if err := watcher.Add(filename); err != nil {
1194 capture(err)
1195 }
1196 <-done
1197}
1198
1199func main() {
1200 cfg, err := loadConfig(configFile)

Callers 1

mainFunction · 0.85

Calls 2

captureFunction · 0.85
captureFuncFunction · 0.85

Tested by

no test coverage detected