aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-12-05 02:35:40 +0100
committerGitHub <noreply@github.com>2022-12-05 02:35:40 +0100
commit0b60344d4b648027ceb657dcd03aed9c3bfa8b58 (patch)
treeb2c890659f96107745a22df1f6efc4b603bf94db /lua
parentfeat: show warning message when exiting neovim with active installations (#725) (diff)
downloadmason-0b60344d4b648027ceb657dcd03aed9c3bfa8b58.tar
mason-0b60344d4b648027ceb657dcd03aed9c3bfa8b58.tar.gz
mason-0b60344d4b648027ceb657dcd03aed9c3bfa8b58.tar.bz2
mason-0b60344d4b648027ceb657dcd03aed9c3bfa8b58.tar.lz
mason-0b60344d4b648027ceb657dcd03aed9c3bfa8b58.tar.xz
mason-0b60344d4b648027ceb657dcd03aed9c3bfa8b58.tar.zst
mason-0b60344d4b648027ceb657dcd03aed9c3bfa8b58.zip
feat(terminator): send SIGKILL after some delay after SIGTERM (#727)
Give a very generous grace period for processes to terminate gracefully before forcefully killing them, to ensure none linger.
Diffstat (limited to 'lua')
-rw-r--r--lua/mason/init.lua2
-rw-r--r--lua/mason/terminator.lua45
2 files changed, 26 insertions, 21 deletions
diff --git a/lua/mason/init.lua b/lua/mason/init.lua
index f6c46ef4..62a66bea 100644
--- a/lua/mason/init.lua
+++ b/lua/mason/init.lua
@@ -16,7 +16,7 @@ local function setup_autocmds()
vim.api.nvim_create_autocmd("VimLeavePre", {
callback = function()
- require("mason.terminator").terminate()
+ require("mason.terminator").terminate(5000)
end,
once = true,
})
diff --git a/lua/mason/terminator.lua b/lua/mason/terminator.lua
index 7a9290a0..ea4bd5a2 100644
--- a/lua/mason/terminator.lua
+++ b/lua/mason/terminator.lua
@@ -22,21 +22,32 @@ local M = {}
---@async
---@param handles InstallHandle[]
-local function terminate_handles(handles)
+---@param grace_ms integer
+local function terminate_handles(handles, grace_ms)
a.wait_all(vim.tbl_map(
---@param handle InstallHandle
function(handle)
- if not handle:is_closed() then
- handle:terminate()
- end
return function()
- a.wait(function(resolve)
- if handle:is_closed() then
- resolve()
- else
- handle:once("closed", resolve)
- end
- end)
+ a.wait_first {
+ function()
+ if not handle:is_closed() then
+ handle:terminate()
+ end
+ a.wait(function(resolve)
+ if handle:is_closed() then
+ resolve()
+ else
+ handle:once("closed", resolve)
+ end
+ end)
+ end,
+ function()
+ a.sleep(grace_ms)
+ if not handle:is_closed() then
+ handle:kill(9) -- SIGKILL
+ end
+ end,
+ }
end
end,
handles
@@ -57,7 +68,8 @@ function M.setup()
end)
end
-function M.terminate()
+---@param grace_ms integer
+function M.terminate(grace_ms)
local handles = vim.tbl_keys(active_handles)
if #handles > 0 then
local package_names = vim.tbl_map(function(h)
@@ -76,14 +88,7 @@ function M.terminate()
-- 2. Synchronously terminate all installation handles.
a.run_blocking(function()
- a.wait_first {
- function()
- a.sleep(5000)
- end,
- function()
- terminate_handles(handles)
- end,
- }
+ terminate_handles(handles, grace_ms)
end)
-- 3. Schedule error message to be displayed so that Neovim prints it to the tty.