refactor(util): reuse timer handles in Debouncer
This commit is contained in:
+3
-13
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user