Skip to content

Commit

Permalink
refactor: handle the process handle
Browse files Browse the repository at this point in the history
  • Loading branch information
vyfor committed Dec 24, 2024
1 parent 85781a2 commit edf1a1b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lua/cord/update/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,32 @@ end
local function get_version(executable, callback)
local uv = vim.loop or vim.uv

local handle = uv.new_pipe()
uv.spawn(executable, {
local stdout = uv.new_pipe()
local handle
handle = uv.spawn(executable, {
args = { '-v' },
stdio = { nil, handle, nil },
stdio = { nil, stdout, nil },
}, function(code, _)
if code == 0 then
handle:read_start(function(_, data)
stdout:read_start(function(_, data)
local version
if data then version = data:gsub('^%s*(.-)%s*$', '%1') end
stdout:close()
handle:close()
callback(version)
end)
else
stdout:close()
handle:close()
callback()
end
end)

if not handle then
stdout:close()
logger.error 'Failed to spawn executable process'
vim.g.cord_is_updating = false
end
end

local function fetch(callback)
Expand Down

0 comments on commit edf1a1b

Please sign in to comment.