From 7fed961fcd09c4d8cf05f34660ab988140d62bd1 Mon Sep 17 00:00:00 2001 From: Ben Lubar Date: Tue, 11 Jul 2017 15:10:42 -0500 Subject: [PATCH] Make repeatUtil.cancel work even when called from the callback. Closes #1122. --- library/lua/repeat-util.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/library/lua/repeat-util.lua b/library/lua/repeat-util.lua index a7ccbefaa..c229ea70d 100644 --- a/library/lua/repeat-util.lua +++ b/library/lua/repeat-util.lua @@ -17,7 +17,9 @@ function cancel(name) if not repeating[name] then return false end - dfhack.timeout_active(repeating[name],nil) + if repeating[name] ~= -1 then + dfhack.timeout_active(repeating[name],nil) + end repeating[name] = nil return true end @@ -26,8 +28,11 @@ function scheduleEvery(name,time,timeUnits,func) cancel(name) local function helper() func() - repeating[name] = dfhack.timeout(time,timeUnits,helper) + if repeating[name] then + repeating[name] = dfhack.timeout(time,timeUnits,helper) + end end + repeating[name] = -1 helper() end