fix: Close async oneshot jobs on finder:close (#1140)
This commit is contained in:
@@ -4,6 +4,8 @@ local LinesPipe = require("telescope._").LinesPipe
|
|||||||
|
|
||||||
local make_entry = require "telescope.make_entry"
|
local make_entry = require "telescope.make_entry"
|
||||||
|
|
||||||
|
local await_count = 1000
|
||||||
|
|
||||||
return function(opts)
|
return function(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
@@ -18,9 +20,14 @@ return function(opts)
|
|||||||
local job_completed = false
|
local job_completed = false
|
||||||
local stdout = nil
|
local stdout = nil
|
||||||
|
|
||||||
|
local job
|
||||||
|
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
-- close = function() results = {}; job_started = false end,
|
close = function()
|
||||||
close = function() end,
|
if job then
|
||||||
|
job:close()
|
||||||
|
end
|
||||||
|
end,
|
||||||
results = results,
|
results = results,
|
||||||
}, {
|
}, {
|
||||||
__call = function(_, prompt, process_result, process_complete)
|
__call = function(_, prompt, process_result, process_complete)
|
||||||
@@ -36,7 +43,7 @@ return function(opts)
|
|||||||
-- end
|
-- end
|
||||||
|
|
||||||
stdout = LinesPipe()
|
stdout = LinesPipe()
|
||||||
local _ = async_job.spawn {
|
job = async_job.spawn {
|
||||||
command = job_opts.command,
|
command = job_opts.command,
|
||||||
args = job_opts.args,
|
args = job_opts.args,
|
||||||
cwd = cwd,
|
cwd = cwd,
|
||||||
@@ -48,9 +55,13 @@ return function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not job_completed then
|
if not job_completed then
|
||||||
for line in stdout:iter(true) do
|
for line in stdout:iter(false) do
|
||||||
num_results = num_results + 1
|
num_results = num_results + 1
|
||||||
|
|
||||||
|
if num_results % await_count then
|
||||||
|
async.util.scheduler()
|
||||||
|
end
|
||||||
|
|
||||||
local v = entry_maker(line)
|
local v = entry_maker(line)
|
||||||
results[num_results] = v
|
results[num_results] = v
|
||||||
process_result(v)
|
process_result(v)
|
||||||
@@ -65,7 +76,9 @@ return function(opts)
|
|||||||
local current_count = num_results
|
local current_count = num_results
|
||||||
for index = 1, current_count do
|
for index = 1, current_count do
|
||||||
-- TODO: Figure out scheduling...
|
-- TODO: Figure out scheduling...
|
||||||
async.util.scheduler()
|
if index % await_count then
|
||||||
|
async.util.scheduler()
|
||||||
|
end
|
||||||
|
|
||||||
if process_result(results[index]) then
|
if process_result(results[index]) then
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -385,6 +385,7 @@ function Picker:find()
|
|||||||
while true do
|
while true do
|
||||||
-- Wait for the next input
|
-- Wait for the next input
|
||||||
rx.last()
|
rx.last()
|
||||||
|
await_schedule()
|
||||||
|
|
||||||
self:_reset_track()
|
self:_reset_track()
|
||||||
|
|
||||||
@@ -1125,6 +1126,10 @@ function pickers.on_close_prompt(prompt_bufnr)
|
|||||||
picker.previewer:teardown()
|
picker.previewer:teardown()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if picker.finder then
|
||||||
|
picker.finder:close()
|
||||||
|
end
|
||||||
|
|
||||||
picker.close_windows(status)
|
picker.close_windows(status)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user