gonotify
gonotify copied to clipboard
Config reload
Hi,
I am using gonotify as source of file events and I am writing config reload for my cli app. Could you give me some hints how to shutdown notifier cleanly?
Ok, I've done it with extra channel to communicate reload and break the select loop. But don't know if this is clean enough.
for !tracker.exit {
log.Debug().Msg("LOOP")
select {
case a, ok := <-fw.Reload:
log.Trace().Msgf("<-fw.Reload.received a %v ok %v", a, ok)
if !ok {
log.Trace().Msgf("<-fw.Reload.!ok: %v", !ok)
}
if a {
tracker.triggerExit()
}
And
func NewInotifyWatcher(ctx context.Context, fileMask uint32, roots []string) (*InotifyWatcher, *context.CancelFunc, error) {
log.Trace().Msgf("%v", fileMask)
f := &InotifyWatcher{
C: make(chan gonotify.FileEvent),
Reload: make(chan bool),
}
ctx, cancel := context.WithCancel(ctx)