diff clock.ur @ 10:0337f88f2efc

Clock
author Adam Chlipala <adam@chlipala.net>
date Fri, 22 Jul 2011 15:40:03 -0400
parents
children ccd0a169e827
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/clock.ur	Fri Jul 22 15:40:03 2011 -0400
@@ -0,0 +1,22 @@
+(** Reactive view of the current time *)
+
+type t = { Source : source time,
+           Period : int }
+
+fun create ms =
+    tm <- now;
+    t <- source tm;
+    return {Source = t, Period = ms}
+
+fun start t =
+    let
+        fun loop () =
+            sleep t.Period;
+            tm <- now;
+            set t.Source tm;
+            loop ()
+    in
+        spawn (loop ())
+    end
+
+fun signal t = Basis.signal t.Source