From 8fbc2d92c6d9e80e3e2a6000022df8dc4256043a Mon Sep 17 00:00:00 2001 From: Anatolii Sakhnik Date: Thu, 3 Aug 2023 17:06:38 +0300 Subject: [PATCH] Avoid using interval timer because it's inconclusive about current state --- lib/proxy/impl.lua | 26 +++++++++++++++++++------- test/70_quickfix_spec.lua | 4 ++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/proxy/impl.lua b/lib/proxy/impl.lua index ac62ae2c..48af2afa 100644 --- a/lib/proxy/impl.lua +++ b/lib/proxy/impl.lua @@ -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 @@ -233,6 +244,7 @@ function ProxyImpl:process_request() end self:process_request() end)) + return true end ---Send a response back to the requester diff --git a/test/70_quickfix_spec.lua b/test/70_quickfix_spec.lua index 6644c066..2d991fa2 100644 --- a/test/70_quickfix_spec.lua +++ b/test/70_quickfix_spec.lua @@ -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') @@ -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')