mirror of
https://github.com/ray-x/navigator.lua
synced 2024-11-05 12:00:21 +00:00
5cf1459e03
* bugfix ts context not shown for off-page entries * logs cleanup * vim.loop -> vim.uv
35 lines
617 B
Lua
35 lines
617 B
Lua
local M = {}
|
|
local uv = vim.uv or vim.loop
|
|
|
|
function M.debounce_trailing(ms, fn)
|
|
local timer = uv.new_timer()
|
|
return function(...)
|
|
local argv = {...}
|
|
if timer:is_active() then
|
|
timer:stop()
|
|
return
|
|
end
|
|
timer:start(ms, 0, function()
|
|
timer:stop()
|
|
fn(unpack(argv))
|
|
end)
|
|
end
|
|
end
|
|
|
|
function M.throttle_leading(ms, fn)
|
|
local timer = uv.new_timer()
|
|
local running = false
|
|
return function(...)
|
|
if not running then
|
|
timer:start(ms, 0, function()
|
|
running = false
|
|
timer:stop()
|
|
end)
|
|
running = true
|
|
fn(...)
|
|
end
|
|
end
|
|
end
|
|
|
|
return M
|