gonotify icon indicating copy to clipboard operation
gonotify copied to clipboard

Config reload

Open akemrir opened this issue 2 years ago • 1 comments

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?

akemrir avatar Apr 14 '23 07:04 akemrir

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)

akemrir avatar Apr 18 '23 14:04 akemrir