refactor: Move debounce function to the utils

This commit is contained in:
simrat39
2021-08-22 16:38:26 -07:00
parent c81d6e87c9
commit 2932c11e92
2 changed files with 26 additions and 23 deletions

View File

@@ -0,0 +1,19 @@
local M = {}
--- @param f function
--- @param delay number
--- @return function
function M.debounce(f, delay)
local timer = vim.loop.new_timer()
return function (...)
local args = { ... }
timer:start(delay, 0, vim.schedule_wrap(function ()
timer:stop()
f(unpack(args))
end))
end
end
return M