changeset 10:0337f88f2efc

Clock
author Adam Chlipala <adam@chlipala.net>
date Fri, 22 Jul 2011 15:40:03 -0400
parents 1e04008eaef7
children ccd0a169e827
files clock.ur clock.urs lib.urp
diffstat 3 files changed, 34 insertions(+), 0 deletions(-) [+]
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/clock.urs	Fri Jul 22 15:40:03 2011 -0400
@@ -0,0 +1,11 @@
+(** Reactive view of the current time *)
+
+type t
+
+val create : int -> transaction t
+(* Specify the clock resolution, in milliseconds. *)
+
+val start : t -> transaction {}
+(* Call this in client-side code (e.g., 'onload' handler) to begin. *)
+
+val signal : t -> signal time
--- a/lib.urp	Tue Jun 21 17:32:36 2011 -0430
+++ b/lib.urp	Fri Jul 22 15:40:03 2011 -0400
@@ -12,3 +12,4 @@
 togglePanel
 popupNav
 navigation
+clock