mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-20 13:26:45 +00:00
feat(build): build files and functions are now async. use coroutine.yield to interrupt and report progress
This commit is contained in:
parent
fcfd54835d
commit
368747bc9a
4 changed files with 102 additions and 38 deletions
|
@ -74,6 +74,32 @@ function Task:start()
|
|||
self:_check()
|
||||
end
|
||||
|
||||
---@param fn async fun()
|
||||
function Task:async(fn)
|
||||
local co = coroutine.create(fn)
|
||||
local check = vim.uv.new_check()
|
||||
check:start(vim.schedule_wrap(function()
|
||||
local status = coroutine.status(co)
|
||||
if status == "dead" then
|
||||
check:stop()
|
||||
self:_check()
|
||||
elseif status == "suspended" then
|
||||
local ok, res = coroutine.resume(co)
|
||||
if not ok then
|
||||
error(res)
|
||||
elseif res then
|
||||
self.status = res
|
||||
self.output = self.output .. "\n" .. res
|
||||
vim.api.nvim_exec_autocmds("User", { pattern = "LazyRender", modeline = false })
|
||||
end
|
||||
end
|
||||
end))
|
||||
|
||||
table.insert(self._running, function()
|
||||
return check:is_active()
|
||||
end)
|
||||
end
|
||||
|
||||
---@private
|
||||
function Task:_check()
|
||||
for _, state in ipairs(self._running) do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue