Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/common/timer.js
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
function updateTimers() | function updateTimers() | ||||
{ | { | ||||
g_Time = Date.now(); | g_Time = Date.now(); | ||||
// Collect the timers that need to run | // Collect the timers that need to run | ||||
// (We do this in two stages to avoid deleting from the timer list while | // (We do this in two stages to avoid deleting from the timer list while | ||||
// we're in the middle of iterating through it) | // we're in the middle of iterating through it) | ||||
var run = []; | var run = []; | ||||
for (var id in g_Timers) | for (let id in g_Timers) | ||||
{ | |||||
if (g_Timers[id][0] <= g_Time) | if (g_Timers[id][0] <= g_Time) | ||||
run.push(id); | run.push(id); | ||||
} | |||||
for (var id of run) | for (let id of run) | ||||
{ | { | ||||
var t = g_Timers[id]; | let t = g_Timers[id]; | ||||
if (!t) | if (!t) | ||||
continue; // an earlier timer might have cancelled this one, so skip it | continue; // an earlier timer might have cancelled this one, so skip it | ||||
try { | try { | ||||
t[1](); | t[1](); | ||||
} catch (e) { | } catch (e) { | ||||
var stack = e.stack.trimRight().replace(/^/mg, ' '); // indent the stack trace | var stack = e.stack.trimRight().replace(/^/mg, ' '); // indent the stack trace | ||||
error(sprintf("Error in timer: %(error)s", { error: e })+"\n"+stack+"\n"); | error(sprintf("Error in timer: %(error)s", { "error": e }) + "\n" + stack + "\n"); | ||||
} | } | ||||
delete g_Timers[id]; | delete g_Timers[id]; | ||||
} | } | ||||
} | } |
Wildfire Games · Phabricator