Skip to content

Commit

Permalink
fix: cancel old render tasks on setup
Browse files Browse the repository at this point in the history
If setup is called multiple times, we need to remove old render tasks so
they don't conflict with the new ones.

See #277
  • Loading branch information
rcarriga committed Sep 10, 2023
1 parent 0ce9978 commit 34160a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lua/dapui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ end
---@eval return require('dapui.config')._format_default()
---@param user_config? dapui.Config
function dapui.setup(user_config)
util.stop_render_tasks()

config.setup(user_config)

local client = require("dapui.client")(dap.session)
Expand Down
11 changes: 10 additions & 1 deletion lua/dapui/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ local M = {}

local api = async.api

local render_tasks = {}

function M.stop_render_tasks()
for _, task in ipairs(render_tasks) do
task.cancel()
end
render_tasks = {}
end

---@return function
function M.create_render_loop(render)
local render_event = async.control.event()

async.run(function()
render_tasks[#render_tasks + 1] = async.run(function()
while true do
render_event.wait()
render_event.clear()
Expand Down

0 comments on commit 34160a7

Please sign in to comment.