refactor(util): reuse timer handles in Debouncer

This commit is contained in:
2026-04-15 21:16:48 +02:00
parent 9c6130d3d2
commit 227900d81c
3 changed files with 63 additions and 45 deletions
+3 -13
View File
@@ -187,17 +187,7 @@ function M.watch()
local plugins_dir = vim.fs.joinpath(config_dir, "plugins")
local err_msg, err_name
watcher, err_msg, err_name = vim.uv.new_fs_event()
if not watcher then
log.error(
"Failed to create fs event watcher: %s (%s)",
err_msg,
err_name
)
return
end
watcher = assert(vim.uv.new_fs_event())
reload = util.debounce(function(filename)
local path = vim.fs.joinpath(plugins_dir, filename)
if not vim.uv.fs_stat(path) then
@@ -211,7 +201,7 @@ function M.watch()
end
end, 100)
watcher:start(plugins_dir, {}, function(err, filename)
assert(watcher:start(plugins_dir, {}, function(err, filename)
if err then
log.error("Watch error: %s", err)
return
@@ -220,7 +210,7 @@ function M.watch()
return
end
reload:call(filename)
end)
end))
end
function M.unwatch()