Skip to content

Commit

Permalink
feat(util): added trackfn that wraps a function and tracks timings
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jan 2, 2023
1 parent 2d06faa commit 50a456c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lua/lazy/core/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ function M.track(data, time)
end
end

---@generic F: fun()
---@param data (string|{[string]:string})?
---@param fn F
---@return F
function M.trackfn(data, fn)
return function(...)
M.track(data)
local ok, ret = pcall(fn, ...)
M.track()
if not ok then
error(ret)
end
return ret
end
end

---@param name string
---@return string
function M.normname(name)
Expand Down Expand Up @@ -127,7 +143,7 @@ function M.very_lazy()
local function _load()
vim.defer_fn(function()
vim.cmd("do User VeryLazy")
end, 100)
end, 50)
end

vim.api.nvim_create_autocmd("User", {
Expand Down

0 comments on commit 50a456c

Please sign in to comment.