Skip to content

Commit

Permalink
fix(status): update checking
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Dec 22, 2024
1 parent ff1bf53 commit 4c0ba67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
17 changes: 12 additions & 5 deletions lua/pckr/async.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ function M.wait(argc, func, ...)
end

--- Creates an async function with a callback style function.
--- @generic F: function
--- @param argc integer
--- @param func function
--- @return function
--- @param func F
--- @return F
function M.wrap(argc, func)
assert(type(argc) == 'number')
assert(type(func) == 'function')
Expand All @@ -122,19 +123,22 @@ function M.sync(nargs, func)
end
end

--- @async
--- @generic R
--- @param n integer Mx number of jobs to run concurrently
--- @param thunks (fun(cb: function): R)[]
--- @param interrupt_check fun()?
--- @param callback fun(ret: R[][])
--- @param interrupt_check (fun(): boolean?)?
--- @param callback? fun(ret: R[][])
--- @return any[][]
M.join = M.wrap(4, function(n, thunks, interrupt_check, callback)
--- @cast callback -?
n = math.min(n, #thunks)

local ret = {} --- @type any[][]

if #thunks == 0 then
callback(ret)
return
return ret
end

local remaining = { unpack(thunks, n + 1) }
Expand All @@ -156,6 +160,8 @@ M.join = M.wrap(4, function(n, thunks, interrupt_check, callback)
for i = 1, n do
thunks[i](cb)
end

return ret
end)

---Useful for partially applying arguments to an async function
Expand All @@ -177,6 +183,7 @@ end

---An async function that when called will yield to the Neovim scheduler to be
---able to call the API.
--- @type fun()
M.schedule = M.wrap(1, vim.schedule)

return M
5 changes: 2 additions & 3 deletions lua/pckr/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,9 @@ function M.run()

disp:update_headline_message(fmt('Checking for updates %d / %d plugins', #tasks, #tasks))

--- @type {[1]: string?, [2]: string?}[]
async.join(limit, function()
async.join(limit, tasks, function()
return disp:check()
end, tasks)
end)

disp:update_headline_message(
fmt('Total plugins: %d (%.2fms)', vim.tbl_count(plugins_by_name), pckr_time)
Expand Down

0 comments on commit 4c0ba67

Please sign in to comment.