Last active
December 11, 2019 20:42
-
-
Save ironcladlou/214faee8286bedfd05e47733427a53d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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