This commit is contained in:
hrsh7th
2022-01-31 14:27:33 +09:00
parent f4bb6ffdb1
commit 0d23640fb6
2 changed files with 39 additions and 28 deletions

View File

@@ -3,6 +3,7 @@ local async = {}
---@class cmp.AsyncThrottle
---@field public running boolean
---@field public timeout number
---@field public sync function(self: cmp.AsyncThrottle, timeout: number|nil)
---@field public stop function
---@field public __call function
@@ -15,6 +16,11 @@ async.throttle = function(fn, timeout)
return setmetatable({
running = false,
timeout = timeout,
sync = function(self, timeout_)
vim.wait(timeout_ or 1000, function()
return not self.running
end)
end,
stop = function()
time = nil
timer:stop()