fix(lua): highlight.on_yank can close timer in twice #18976

check whether timer is closing in vim.defer_fn before closing
This commit is contained in:
notomo
2022-06-16 11:39:55 +09:00
committed by Christian Clason
parent f15d6094fc
commit fe42dea674
2 changed files with 19 additions and 6 deletions

View File

@@ -373,9 +373,13 @@ end
function vim.defer_fn(fn, timeout)
vim.validate { fn = { fn, 'c', true}; }
local timer = vim.loop.new_timer()
timer:start(timeout, 0, vim.schedule_wrap(function()
timer:stop()
timer:close()
timer:start(
timeout,
0,
vim.schedule_wrap(function()
if not timer:is_closing() then
timer:close()
end
fn()
end))