From e54842961ec017bb60a3da5cf2aa746e0d29e6ca Mon Sep 17 00:00:00 2001 From: cukmekerb Date: Thu, 8 Apr 2021 21:59:02 -0700 Subject: fixed autosave coroutine issue --- plugins/autosave.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'plugins/autosave.lua') diff --git a/plugins/autosave.lua b/plugins/autosave.lua index 11337f7..4c39612 100644 --- a/plugins/autosave.lua +++ b/plugins/autosave.lua @@ -13,18 +13,15 @@ config.autosave_timeout = 1 local function loop_for_save() - if not looping then - looping = true while looping do if os.difftime(os.time(), last_keypress) >= config.autosave_timeout then command.perform "doc:save" -- stop loop looping = false end - -- dividing by five is completely arbitrary but it seemed to work well so idc + -- wait the timeout. may cause timeout to be slightly imprescise coroutine.yield(config.autosave_timeout) end - end end @@ -32,7 +29,10 @@ local function updatepress() -- set last keypress time to now last_keypress = os.time() -- put loop in coroutine so it doesn't lag out this script - core.add_thread(loop_for_save) + if not looping then + looping = true + core.add_thread(loop_for_save) + end end -- cgit v1.2.3