Skip to content

Commit

Permalink
Avoid using interval timer because it's inconclusive about current state
Browse files Browse the repository at this point in the history
  • Loading branch information
sakhnik committed Aug 3, 2023
1 parent a243679 commit 8fbc2d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
26 changes: 19 additions & 7 deletions lib/proxy/impl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,33 @@ function ProxyImpl:on_stdout(data1, data2)
else
io.stdout:write(data1, data2)
end
self.stdout_timer:stop()
self.stdout_timer:start(100, 100, vim.schedule_wrap(function()
self:process_request()
end))
local function start_stdout_timer()
self.stdout_timer:stop()
self.stdout_timer:start(100, 0, vim.schedule_wrap(function()
if self:process_request() then
self.stdout_timer:stop()
else
-- There're still requests to be scheduled
-- Note, that interval timer returns deceptional get_due_in(),
-- which is >0 after the timer has been stopped until the first interval elapses.
-- Therefore no intervals, restarting the timer manually
start_stdout_timer()
end
end))
start_stdout_timer()
end
end

---Check if there's an outstanding request and start executing it
---@private
---@return boolean false if there's an outstanding request, but it can't be scheduled at the moment
function ProxyImpl:process_request()
log.debug({"ProxyImpl:process_request"})
if self.current_request ~= nil then
return
return false
end
self.stdout_timer:stop()
if self.request_queue_tail == self.request_queue_head then
return
return true
end
local command = self.request_queue[self.request_queue_head]
self.request_queue[self.request_queue_head] = nil
Expand All @@ -233,6 +244,7 @@ function ProxyImpl:process_request()
end
self:process_request()
end))
return true
end

---Send a response back to the requester
Expand Down
4 changes: 2 additions & 2 deletions test/70_quickfix_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("quickfix", function()

end)

it('breakpoint location list in PDB', function()
it('breakpoint location list in pdb', function()
conf.post_terminal_end(function()
conf.count_stops(function(count_stops)
eng.feed(' dp<cr>')
Expand Down Expand Up @@ -115,7 +115,7 @@ describe("quickfix", function()
end)
end)

it('backtrace location list in PDB', function()
it('backtrace location list in pdb', function()
conf.post_terminal_end(function()
conf.count_stops(function(count_stops)
eng.feed(' dp<cr>')
Expand Down

0 comments on commit 8fbc2d9

Please sign in to comment.