koanf icon indicating copy to clipboard operation
koanf copied to clipboard

How to stop file watcher?

Open halturin opened this issue 2 years ago • 3 comments

couldn't find a way to stop file-watching.

f := file.Provider("somefile.yaml"))

f.Watch(func(event any, e error) error {
  // handler
}

am I missing something?

halturin avatar Oct 27 '23 07:10 halturin

You're right, there's no way to currently stop watching files. Please feel free to send a PR. Perhaps an f.Unwatch().

knadh avatar Oct 27 '23 07:10 knadh

not sure if I have enough spare time in the near future. but if I implemented this feature, I would update the Provider interface by adding

Watch(func(...) error) error // returns error if doesn't support
Unwatch() error // same here

methods to make it more unified

halturin avatar Oct 27 '23 09:10 halturin

Hi @knadh , If this issue is still open would you mind taking a look at my PR https://github.com/knadh/koanf/pull/245. I have tried implementing the unwatch function for file provider. let me know if you feel any changes are to be made...

prateek-narsinghani avatar Oct 31 '23 17:10 prateek-narsinghani