feat(build): build files and functions are now async. use coroutine.yield to interrupt and report progress

This commit is contained in:
Folke Lemaitre 2024-06-24 14:16:00 +02:00
parent fcfd54835d
commit 368747bc9a
4 changed files with 102 additions and 38 deletions

View file

@ -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