0 votes
1.1k views
by (21.5k points)

1 Answer

0 votes
ago by (30.6k points)

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

Related questions

0 votes
1 answer 715 views
0 votes
1 answer 1.3k views
0 votes
1 answer 1.3k views
0 votes
1 answer 849 views
0 votes
1 answer 895 views
0 votes
1 answer 787 views
0 votes
2 answers 3.1k views
0 votes
1 answer 706 views
0 votes
1 answer 1.5k views
0 votes
1 answer 2.4k views
0 votes
1 answer 2.5k views
0 votes
1 answer 1.2k views
0 votes
1 answer 1.4k views
0 votes
1 answer 526 views

723 questions

807 answers

98 comments

4.9k users

Join BPM Community Discord Channel

Welcome to BPM Tips Q&A, Community wiki/forum where you can ask questions and receive answers from other IBM BPM experts and members of the community. Users with 2000 points will automatically be promoted to expert level.
Created by Dosvak LLC
Our Youtube Channel
...