rework scheduler to use vim.uv; fall back to vim.loop

This commit is contained in:
raf 2025-03-09 01:34:59 +03:00
commit a9fea11133
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -191,12 +191,22 @@ end
--- Debounced update function
function M.schedule_update()
local uv = vim.uv or vim.loop
-- Properly clean up the previous timer before creating a new one.
-- Do NOT move this block below `uv.new_timer()`, or the new timer
-- will be stopped and closed immediately after being created.
if timer then
timer:stop()
timer:close()
if timer.stop then timer:stop() end
if timer.close then timer:close() end
end
timer = uv.new_timer()
-- Ensure the new timer is valid before starting it.
if timer then
timer:start(config.debounce_delay, 0, vim.schedule_wrap(M.update_decorations))
end
timer = vim.loop.new_timer()
timer:start(config.debounce_delay, 0, vim.schedule_wrap(M.update_decorations))
end
return M