common-utils.lua: use different timeout callbacks for different states
This allows saving different states at the same time.
This commit is contained in:
@@ -102,16 +102,20 @@ function cutils.arrayContains (a, value)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
state_save_sources = {}
|
||||||
|
|
||||||
function cutils.storeAfterTimeout (state, state_table)
|
function cutils.storeAfterTimeout (state, state_table)
|
||||||
if timeout_source then
|
local state_name = state["name"]
|
||||||
timeout_source:destroy ()
|
if state_save_sources [state_name] ~= nil then
|
||||||
|
state_save_sources [state_name]:destroy ()
|
||||||
|
state_save_sources [state_name] = nil
|
||||||
end
|
end
|
||||||
local timeout_source = Core.timeout_add (1000, function ()
|
state_save_sources [state_name] = Core.timeout_add (1000, function ()
|
||||||
local saved, err = state:save (state_table)
|
local saved, err = state:save (state_table)
|
||||||
if not saved then
|
if not saved then
|
||||||
Log.warning (err)
|
Log.warning (err)
|
||||||
end
|
end
|
||||||
timeout_source = nil
|
return false
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user