4 * @copy Copyright (c) Mbedthis Software LLC, 2005-2006. All Rights Reserved.
7 * timer = new System.Timer("name", period);
8 * timer.onTick = function(arg) {
14 * timer = new System.Timer("name", period, obj, method);
18 /******************************************************************************/
24 /* MOB -- really need accessor on period. If user updates period,
25 then due must be updated. */
28 var runOnce; // Run timer just once
29 var method; // Callback method
30 var obj; // Callback object
32 function Timer(id, period, obj, method)
36 due = time() + period;
38 if (arguments.length >= 3) {
43 if (arguments.length >= 4) {
46 this.method = "onTick";
50 /* MOB this should be deprecated */
51 function reschedule(period)
53 /* MOB -- should update the timer service somehow */
59 if (obj[method] == undefined) {
60 trace("Timer cant find timer method " + method);
61 due = now + this.period;
72 trace("Timer exception: " + error);
76 timerService.removeTimer(this);
79 due = now + this.period;
85 if (obj[method] == undefined) {
86 throw new Error("Callback method is undefined");
88 timerService.addTimer(this);
94 timerService.removeTimer(this);
99 /* MOB -- should not need this */
100 Timer = System.Timer;
106 class System.TimerService
111 function TimerService()
113 timers = new Object();
115 global.timerService = this;
118 function addTimer(timer)
120 timers[timer.id] = timer;
123 function removeTimer(timer)
126 delete timers[timer.id];
131 function getIdleTime()
133 return nextDue - time();
140 nextDue = 2147483647; /* MOB -- MATH.MAX_INT; */
142 for each (var timer in timers)
144 if (timer.due < now) {
148 for each (var timer in timers)
150 if (timer.due < nextDue) {
154 // println("runTimers leaving with " + (nextDue - now));
155 return nextDue - time();
158 TimerService = System.TimerService;