[Gd-chatter] r11019 - trunk/libraries/timer

hannes at gwydiondylan.org hannes at gwydiondylan.org
Sun Dec 3 00:43:56 CET 2006


Author: hannes
Date: Sun Dec  3 00:43:53 2006
New Revision: 11019

Added:
   trunk/libraries/timer/recurrent-timer.dylan   (contents, props changed)
Modified:
   trunk/libraries/timer/timer-exports.dylan
   trunk/libraries/timer/timer-test.dylan
   trunk/libraries/timer/timer.lid
Log:
Bug: 7299
*added a <recurrent-timer> which calls it's event in a given interval

Added: trunk/libraries/timer/recurrent-timer.dylan
==============================================================================
--- (empty file)
+++ trunk/libraries/timer/recurrent-timer.dylan	Sun Dec  3 00:43:53 2006
@@ -0,0 +1,22 @@
+module: timer
+synopsis: 
+author: 
+copyright: 
+
+define class <recurrent-timer> (<object>)
+  constant slot interval :: <integer>, required-init-keyword: interval:;
+  constant slot real-event :: <function>, required-init-keyword: event:;
+end;
+
+define method initialize (timer :: <recurrent-timer>,
+                          #next next-method,
+                          #rest rest, #key, #all-keys)
+  next-method();
+  make(<timer>, in: timer.interval, event: curry(recurrent-event, timer));
+end;
+
+define method recurrent-event (t :: <recurrent-timer>) => (res)
+  t.real-event();
+  make(<timer>, in: t.interval, event: curry(recurrent-event, t));
+end;
+

Modified: trunk/libraries/timer/timer-exports.dylan
==============================================================================
--- trunk/libraries/timer/timer-exports.dylan	(original)
+++ trunk/libraries/timer/timer-exports.dylan	Sun Dec  3 00:43:53 2006
@@ -16,5 +16,5 @@
   use date;
   use threads;
 
-  export <timer>, cancel;
+  export <timer>, cancel, <recurrent-timer>;
 end module;

Modified: trunk/libraries/timer/timer-test.dylan
==============================================================================
--- trunk/libraries/timer/timer-test.dylan	(original)
+++ trunk/libraries/timer/timer-test.dylan	Sun Dec  3 00:43:53 2006
@@ -1,6 +1,7 @@
 module: timer
 
 define method main ()
+  let timer23 = make(<recurrent-timer>, interval: 2, event: print-foo);
   let timer1 = make(<timer>, in: 1, event: print-date);
   let timer3 = make(<timer>, in: 3, event: print-date);
   let timer8 = make(<timer>, in: 8, event: print-date);
@@ -12,6 +13,9 @@
   sleep(3);
 end;
 
+define method print-foo ()
+  format-out("FOO\n");
+end;
 define method print-date ()
   let date = current-date();
   format-out("%s\n", as-iso8601-string(date));

Modified: trunk/libraries/timer/timer.lid
==============================================================================
--- trunk/libraries/timer/timer.lid	(original)
+++ trunk/libraries/timer/timer.lid	Sun Dec  3 00:43:53 2006
@@ -1,4 +1,5 @@
 library: timer
 files: timer-exports
        timer
+       recurrent-timer
        timer-test



More information about the chatter mailing list