Skip to content

Commit 34160a7

Browse files
committed
fix: cancel old render tasks on setup
If setup is called multiple times, we need to remove old render tasks so they don't conflict with the new ones. See #277
1 parent 0ce9978 commit 34160a7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lua/dapui/init.lua

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ end
7474
---@eval return require('dapui.config')._format_default()
7575
---@param user_config? dapui.Config
7676
function dapui.setup(user_config)
77+
util.stop_render_tasks()
78+
7779
config.setup(user_config)
7880

7981
local client = require("dapui.client")(dap.session)

lua/dapui/util.lua

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ local M = {}
55

66
local api = async.api
77

8+
local render_tasks = {}
9+
10+
function M.stop_render_tasks()
11+
for _, task in ipairs(render_tasks) do
12+
task.cancel()
13+
end
14+
render_tasks = {}
15+
end
16+
817
---@return function
918
function M.create_render_loop(render)
1019
local render_event = async.control.event()
1120

12-
async.run(function()
21+
render_tasks[#render_tasks + 1] = async.run(function()
1322
while true do
1423
render_event.wait()
1524
render_event.clear()

0 commit comments

Comments
 (0)