The Timer control fires an event after an interval, once or repeatedly - the toolkit's replacement for hand-written setInterval code (question 2511).
- Options: Interval (ms), one-shot or repeating, Auto start, Enabled.
- Methods: start(), stop(), reset(), isRunning(), setInterval(ms).
- Event: On timeout (fires at each interval; the handler gets me).
// Timer "Poll" > On timeout: refresh a status every 10 s while the task is open
${GetStatus}.execute(); // Service Call control; its On result fills ${Status}
if (${Status}.getData() === "COMPLETED") { ${Poll}.stop(); ${Next}.setEnabled(true); }
// countdown to the due date
// Timer "Tick" (1000 ms, repeating, auto start) > On timeout:
var left = Math.max(0, Math.round((new Date(${Due}.getData()) - new Date()) / 1000));
${Countdown}.setText(Math.floor(left / 60) + ":" + ("0" + left % 60).slice(-2));
if (left === 0) ${Tick}.stop();Good practice: stop timers on unload / before navigating (the toolkit stops them when the coach is destroyed, but explicit is safer), keep polling intervals long and stop when document.hidden, and never use a coach timer to wait for a server-side event - a BPD timer or an intermediate message event is the right tool there.
References