Asynchronous Reads for Dirmonitor (#930)

Change dirmonitor reads to be synchronous, in a secondary thread.
This commit is contained in:
Adam
2022-04-24 13:40:58 -04:00
committed by GitHub
parent c112bd8d7c
commit 97174706fe
8 changed files with 190 additions and 195 deletions
+4
View File
@@ -85,7 +85,9 @@ end
-- designed to be run inside a coroutine.
function dirwatch:check(change_callback, scan_time, wait_time)
local had_change = false
self.monitor:check(function(id)
had_change = true
if PLATFORM == "Windows" then
change_callback(common.dirname(self.windows_watch_top .. PATHSEP .. id))
elseif self.reverse_watched[id] then
@@ -98,6 +100,7 @@ function dirwatch:check(change_callback, scan_time, wait_time)
local new_modified = system.get_file_info(directory).modified
if old_modified < new_modified then
change_callback(directory)
had_change = true
self.scanned[directory] = new_modified
end
end
@@ -106,6 +109,7 @@ function dirwatch:check(change_callback, scan_time, wait_time)
start_time = system.get_time()
end
end
return had_change
end
+3 -11
View File
@@ -269,7 +269,7 @@ function core.add_project_directory(path)
-- time; the watch will yield in this coroutine after 0.01 second, for 0.1 seconds.
topdir.watch_thread = core.add_thread(function()
while true do
topdir.watch:check(function(target)
local changed = topdir.watch:check(function(target)
if target == topdir.name then return refresh_directory(topdir) end
local dirpath = target:sub(#topdir.name + 2)
local abs_dirpath = topdir.name .. PATHSEP .. dirpath
@@ -280,7 +280,7 @@ function core.add_project_directory(path)
end
return refresh_directory(topdir, dirpath)
end, 0.01, 0.01)
coroutine.yield(0.05)
coroutine.yield(changed and 0.05 or 0)
end
end)
@@ -1116,14 +1116,6 @@ function core.try(fn, ...)
return false, err
end
local scheduled_rescan = {}
function core.has_pending_rescan()
for _ in pairs(scheduled_rescan) do
return true
end
end
function core.on_event(type, ...)
local did_keymap = false
if type == "textinput" then
@@ -1270,8 +1262,8 @@ function core.run()
local idle_iterations = 0
while true do
core.frame_start = system.get_time()
local need_more_work = run_threads()
local did_redraw = core.step()
local need_more_work = run_threads() or core.has_pending_rescan()
if core.restart_request or core.quit_request then break end
if not did_redraw and not need_more_work then
idle_iterations = idle_iterations + 1