Skip to content

Commit

Permalink
Make cleanup pulses actually work (?)
Browse files Browse the repository at this point in the history
Persists the `curl` process for cleanup pulses beyond the end of its
parent `nvim` process.
  • Loading branch information
Shados committed Apr 8, 2019
1 parent fa6a02b commit 1b159d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
16 changes: 11 additions & 5 deletions lua/codestats/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ codestats = {
return self:log("add_xp() called from " .. tostring(event) .. ", filetype: " .. tostring(filetype))
end
end,
pulse_xp = function(self)
pulse_xp = function(self, is_cleanup)
if is_cleanup == nil then
is_cleanup = false
end
if table_.size(self.xps) == 0 then
return
end
self.pulses:push_right(create_pulse(self.xps))
return self:schedule_pulse()
return self:schedule_pulse(is_cleanup)
end,
schedule_pulse = function(self)
schedule_pulse = function(self, is_cleanup)
if self.pulsing then
return
end
Expand Down Expand Up @@ -92,6 +95,9 @@ codestats = {
stdout_buffered = true,
pulse = pulse
}
if is_cleanup then
opts['detach'] = true
end
local args = {
cmd,
opts
Expand Down Expand Up @@ -130,8 +136,8 @@ codestats = {
end
end,
cleanup = function(self)
self:pulse_xp()
return self:log("Launching cleanup pulse; XP will be lost if it fails")
self:log("Launching cleanup pulse; XP will be lost if it fails")
return self:pulse_xp(true)
end,
log = function(self, msg)
if self.logging then
Expand Down
10 changes: 6 additions & 4 deletions moon/codestats/init.moon
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ codestats =
@xps[filetype] += 1
@log "add_xp() called from #{event}, filetype: #{filetype}"

pulse_xp: () =>
pulse_xp: (is_cleanup=false) =>
if table_.size(@xps) == 0
return
-- Create pulse from current xps (clearing current xps), and schedule a pulse
@pulses\push_right(create_pulse @xps)
@schedule_pulse!
@schedule_pulse is_cleanup

schedule_pulse: () =>
schedule_pulse: (is_cleanup) =>
-- Guard against running more than one pulse process at a time
if @pulsing
return
Expand Down Expand Up @@ -107,6 +107,8 @@ codestats =
on_exit: "codestats#pulse_callback"
stdout_buffered: true
pulse: pulse
if is_cleanup
opts['detach'] = true

args = { cmd, opts }
jobid = vimw.fn "jobstart", args
Expand Down Expand Up @@ -137,8 +139,8 @@ codestats =
@schedule_pulse!

cleanup: () =>
@pulse_xp!
@log "Launching cleanup pulse; XP will be lost if it fails"
@pulse_xp true
-- TODO Possibly serialize pulses to a cache file? Do I care that much?

log: (msg) =>
Expand Down

0 comments on commit 1b159d6

Please sign in to comment.