Skip to content

Commit ee6fda7

Browse files
authored
fix(job): remove delay from shutdown (#406)
1 parent c4d6e55 commit ee6fda7

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

lua/plenary/job.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,9 @@ end
211211

212212
--- Shutdown a job.
213213
function Job:shutdown(code, signal)
214-
if self._shutdown_check and not uv.is_active(self._shutdown_check) then
215-
vim.wait(1000, function()
216-
return self:_pipes_are_closed(self) and self.is_shutdown
217-
end, 1, true)
214+
if self._shutdown_check and uv.is_active(self._shutdown_check) then
215+
-- shutdown has already started
216+
return
218217
end
219218

220219
self:_shutdown(code, signal)

tests/plenary/job_spec.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,27 @@ local has_all_executables = function(execs)
1010
return true
1111
end
1212

13+
local tables_equal = function(t1, t2)
14+
if #t1 ~= #t2 then
15+
return false
16+
end
17+
for i, t1_v in ipairs(t1) do
18+
if t2[i] ~= t1_v then
19+
return false
20+
end
21+
end
22+
return true
23+
end
24+
25+
local wait_for_result = function(job, result)
26+
if type(result) == "string" then
27+
result = { result }
28+
end
29+
vim.wait(1000, function()
30+
return tables_equal(job:result(), result)
31+
end)
32+
end
33+
1334
describe("Job", function()
1435
describe("> cat manually >", function()
1536
it("should split simple stdin", function()
@@ -25,6 +46,8 @@ describe("Job", function()
2546
job:start()
2647
job:send "hello\n"
2748
job:send "world\n"
49+
50+
wait_for_result(job, { "hello", "world" })
2851
job:shutdown()
2952

3053
assert.are.same(job:result(), { "hello", "world" })
@@ -46,6 +69,8 @@ describe("Job", function()
4669
job:send "\n"
4770
job:send "world\n"
4871
job:send "\n"
72+
73+
wait_for_result(job, { "hello", "", "world", "" })
4974
job:shutdown()
5075

5176
assert.are.same(job:result(), { "hello", "", "world", "" })
@@ -66,6 +91,8 @@ describe("Job", function()
6691
job:start()
6792
job:send "hello\nwor"
6893
job:send "ld\n"
94+
95+
wait_for_result(job, { "hello", "world" })
6996
job:shutdown()
7097

7198
assert.are.same(job:result(), { "hello", "world" })
@@ -655,6 +682,7 @@ describe("Job", function()
655682
input_pipe:write "job.lua\n"
656683
input_pipe:close()
657684

685+
wait_for_result(fzf, "job.lua")
658686
fzf:shutdown()
659687

660688
local results = fzf:result()
@@ -692,6 +720,7 @@ describe("Job", function()
692720
input_pipe:write "job.lua"
693721
input_pipe:close()
694722

723+
wait_for_result(fzf, "job.lua")
695724
fzf:shutdown()
696725

697726
local results = fzf:result()

0 commit comments

Comments
 (0)