fix: cancel active process on contest switch (#316)
## Problem Switching contests while a run, interactive session, or stress test was active left orphaned callbacks and terminal jobs alive. Running `:CP run` twice also let the first run's stale output overwrite the buffer. ## Solution Replace the `io_view_running` bool in `views.lua` with a generation counter so concurrent `run_io_view` calls self-cancel via stale-gen checks in async callbacks. Add `cancel_io_view`, `cancel_interactive`, and `stress.cancel` for forceful teardown, and call them in `setup_contest` whenever `is_new_contest` is true.
This commit is contained in:
parent
916c9174a6
commit
7e7e135681
3 changed files with 57 additions and 18 deletions
|
|
@ -232,4 +232,18 @@ function M.toggle(generator_cmd, brute_cmd)
|
|||
end)
|
||||
end
|
||||
|
||||
function M.cancel()
|
||||
if state.stress_buf and vim.api.nvim_buf_is_valid(state.stress_buf) then
|
||||
local job = vim.b[state.stress_buf].terminal_job_id
|
||||
if job then
|
||||
vim.fn.jobstop(job)
|
||||
end
|
||||
end
|
||||
if state.saved_stress_session then
|
||||
vim.fn.delete(state.saved_stress_session)
|
||||
state.saved_stress_session = nil
|
||||
end
|
||||
state.set_active_panel(nil)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue