refactor: Move debounce function to the utils
This commit is contained in:
19
lua/symbols-outline/utils/init.lua
Normal file
19
lua/symbols-outline/utils/init.lua
Normal 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
|
||||
Reference in New Issue
Block a user