dirwatch: exit coroutine if project not open anymore to properly gargage collect it (#1142)

This commit is contained in:
Jefferson González 2022-10-11 10:22:44 -07:00 committed by GitHub
parent ec6d0532c8
commit 214c9d6287
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -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)