Make repeatUtil.cancel work even when called from the callback. Closes #1122.

develop
Ben Lubar 2017-07-11 15:10:42 -05:00
parent 070dfa1865
commit 7fed961fcd
No known key found for this signature in database
GPG Key ID: 018BAB45DB2D2B24
1 changed files with 7 additions and 2 deletions

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