fix(timer): correctly handle multi-instance teardown
This commit is contained in:
@@ -328,8 +328,25 @@ function M.teardown()
|
||||
state.uv_timer:close()
|
||||
state.uv_timer = nil
|
||||
end
|
||||
|
||||
if not (state.running and state.timer_id) then
|
||||
cleanup_activity_file()
|
||||
return
|
||||
end
|
||||
|
||||
-- Remove our own timestamp from the shared file (only if we were the last
|
||||
-- writer). After this, other_instance_active() reflects *other* instances only.
|
||||
cleanup_activity_file()
|
||||
if state.running and state.timer_id then
|
||||
|
||||
if other_instance_active() then
|
||||
-- A different session is still actively using this timer: leave it running.
|
||||
notify("Another instance is active — timer left running on exit")
|
||||
else
|
||||
-- No currently-active other instance. However, there may be a surviving
|
||||
-- idle instance (e.g. instance A whose watchdog re-armed because this
|
||||
-- instance was writing activity). Write the "0" sentinel so that instance
|
||||
-- detects the stop on its next user activity and resumes the timer.
|
||||
mark_timer_paused()
|
||||
local ok, err = api.stop_timer(state.token, state.timer_id)
|
||||
if ok then
|
||||
state.running = false
|
||||
|
||||
Reference in New Issue
Block a user