koanf icon indicating copy to clipboard operation
koanf copied to clipboard

adding Unwatch function for file provider

Open prateek-narsinghani opened this issue 2 years ago • 3 comments

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

@rhnvrm , I have made the following changes:

  1. Changed function name UnWatch -> Unwatch
  2. Added comment for the Unwatch function
  3. Using Close function for all the watchers
  4. Adding an array to the file structure as there can be multiple f.Watch() calls, hence an array would store all the watchers

prateek-narsinghani avatar Nov 09 '23 18:11 prateek-narsinghani

@prateek-narsinghani thanks for the PR. Could you please add tests for this as well?

knadh avatar Nov 26 '23 08:11 knadh

@knadh I have added a test for the Unwatch function. Let me know if any further changes are required.

prateek-narsinghani avatar Dec 03 '23 19:12 prateek-narsinghani

I finally got around to looking into this. Please take a look at: https://github.com/knadh/koanf/pull/306

It addresses a couple of issues in this PR:

  • Unwatch() triggers random channel closure errors (main channel or error channel) to the callback, which the caller is expected to handle. Unwatch() shouldn't trigger these errors.
  • The f.w == nil issue where once Unwatched(), the watcher couldn't be used again. Also, setting f.w to nil would require locking.

knadh avatar Jul 17 '24 08:07 knadh