Merge remote-tracking branch 'BenLubar/repeat-util-cancel-self' into develop

develop
lethosor 2017-07-12 16:35:24 -04:00
commit d236181cdc
1 changed files with 7 additions and 2 deletions

@ -17,7 +17,9 @@ function cancel(name)
if not repeating[name] then if not repeating[name] then
return false return false
end end
dfhack.timeout_active(repeating[name],nil) if repeating[name] ~= -1 then
dfhack.timeout_active(repeating[name],nil)
end
repeating[name] = nil repeating[name] = nil
return true return true
end end
@ -26,8 +28,11 @@ function scheduleEvery(name,time,timeUnits,func)
cancel(name) cancel(name)
local function helper() local function helper()
func() func()
repeating[name] = dfhack.timeout(time,timeUnits,helper) if repeating[name] then
repeating[name] = dfhack.timeout(time,timeUnits,helper)
end
end end
repeating[name] = -1
helper() helper()
end end