mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-09 12:20:05 +08:00
perf(job): close job handle on_exit
This commit is contained in:
parent
172b79f658
commit
732401aee9
@ -129,24 +129,41 @@ function M.start(cmd, opts)
|
|||||||
local exit_cb
|
local exit_cb
|
||||||
if opts.on_exit then
|
if opts.on_exit then
|
||||||
exit_cb = function(code, singin)
|
exit_cb = function(code, singin)
|
||||||
if stdout and stdout:is_active() then
|
if stdout and not stdout:is_closing() then
|
||||||
stdout:close()
|
stdout:close()
|
||||||
end
|
end
|
||||||
if stderr and stderr:is_active() then
|
if stderr and not stderr:is_closing() then
|
||||||
stderr:close()
|
stderr:close()
|
||||||
end
|
end
|
||||||
|
if stdin and not stdin:is_closing() then
|
||||||
|
stdin:close()
|
||||||
|
end
|
||||||
|
local job = _jobs['jobid_' .. current_id]
|
||||||
|
|
||||||
|
if job and job.handle and not job.handle:is_closing() then
|
||||||
|
job.handle:close()
|
||||||
|
end
|
||||||
|
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
opts.on_exit(current_id, code, singin)
|
opts.on_exit(current_id, code, singin)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
exit_cb = function(code, singin)
|
exit_cb = function(code, singin)
|
||||||
if stdout and stdout:is_active() then
|
if stdout and not stdout:is_closing() then
|
||||||
stdout:close()
|
stdout:close()
|
||||||
end
|
end
|
||||||
if stderr and stderr:is_active() then
|
if stderr and not stderr:is_closing() then
|
||||||
stderr:close()
|
stderr:close()
|
||||||
end
|
end
|
||||||
|
if stdin and not stdin:is_closing() then
|
||||||
|
stdin:close()
|
||||||
|
end
|
||||||
|
local job = _jobs['jobid_' .. current_id]
|
||||||
|
|
||||||
|
if job and job.handle and not job.handle:is_closing() then
|
||||||
|
job.handle:close()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -257,13 +274,20 @@ function M.chanclose(id, t)
|
|||||||
error('can not find job:' .. id)
|
error('can not find job:' .. id)
|
||||||
end
|
end
|
||||||
if t == 'stdin' then
|
if t == 'stdin' then
|
||||||
-- close stdio
|
|
||||||
local stdin = jobobj.state.stdin
|
local stdin = jobobj.state.stdin
|
||||||
if stdin and stdin:is_active() then
|
if stdin and not stdin:is_closing() then
|
||||||
stdin:close()
|
stdin:close()
|
||||||
end
|
end
|
||||||
elseif t == 'stdout' then
|
elseif t == 'stdout' then
|
||||||
|
local stdout = jobobj.state.stdout
|
||||||
|
if stdout and not stdout:is_closing() then
|
||||||
|
stdout:close()
|
||||||
|
end
|
||||||
elseif t == 'stderr' then
|
elseif t == 'stderr' then
|
||||||
|
local stderr = jobobj.state.stderr
|
||||||
|
if stderr and not stderr:is_closing() then
|
||||||
|
stderr:close()
|
||||||
|
end
|
||||||
else
|
else
|
||||||
error('the type only can be:stdout, stdin or stderr')
|
error('the type only can be:stdout, stdin or stderr')
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user