From 214c9d6287cefe7da3be61020d3cc5b02eb9618b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jefferson=20Gonz=C3=A1lez?= Date: Tue, 11 Oct 2022 10:22:44 -0700 Subject: [PATCH] dirwatch: exit coroutine if project not open anymore to properly gargage collect it (#1142) --- data/core/init.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/data/core/init.lua b/data/core/init.lua index f67e7cad..e72c852e 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -295,7 +295,19 @@ function core.add_project_directory(path) end return refresh_directory(topdir, dirpath) end, 0.01, 0.01) - coroutine.yield(changed and 0.05 or 0) + -- properly exit coroutine if project not open anymore to clear dir watch + local project_dir_open = false + for _, prj in ipairs(core.project_directories) do + if topdir == prj then + project_dir_open = true + break + end + end + if project_dir_open then + coroutine.yield(changed and 0.05 or 0) + else + return + end end end)