comparison changePoller.ur @ 14:0827320b0f04

Write calendarCtl in terms of a source with a listener.
author Karn Kallio <kkallio@eka>
date Fri, 05 Aug 2011 18:55:24 -0430
parents
children
comparison
equal deleted inserted replaced
13:c016beb0ebac 14:0827320b0f04
1 con changePoller t = {Val : source t,
2 Last : source t}
3
4 fun create [t ::: Type] (_ : eq t) (i : t) =
5 v <- source i;
6 l <- source i;
7
8 return {Val = v,
9 Last = l}
10
11 fun addChangeListener [t ::: Type] (_ : eq t) f pollInterval cp =
12 let
13 fun go () =
14 sleep pollInterval;
15 sample <- get cp.Val;
16 lst <- get cp.Last;
17 if sample = lst then
18 go ()
19 else
20 f sample;
21 set cp.Last sample;
22 go ()
23 in
24 go ()
25 end
26
27 fun ctl [t ::: Type] cp = cp.Val
28
29 fun value [t ::: Type] cp = signal (cp.Val)
30