Skip to content

Instantly share code, notes, and snippets.

@ironcladlou
Last active December 11, 2019 20:42
Show Gist options
  • Save ironcladlou/214faee8286bedfd05e47733427a53d8 to your computer and use it in GitHub Desktop.
Save ironcladlou/214faee8286bedfd05e47733427a53d8 to your computer and use it in GitHub Desktop.
stop := make(chan struct{})
go func() {
<-signals.SetupSignalHandler()
stop <- struct{}{}
}()
file := "/wherever"
go func() {
watcher, _ := fsnotify.NewWatcher()
defer watcher.Close()
updated := make(chan bool)
go func() {
orig, _ := ioutil.ReadFile(file)
for {
<-watcher.Events
latest, _ := ioutil.ReadFile(file)
if !bytes.Equal(orig, latest) {
break
}
}
updated <- true
}()
watcher.Add(file)
<-updated
<-stop
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment