annotate 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
rev   line source
kkallio@14 1 con changePoller t = {Val : source t,
kkallio@14 2 Last : source t}
kkallio@14 3
kkallio@14 4 fun create [t ::: Type] (_ : eq t) (i : t) =
kkallio@14 5 v <- source i;
kkallio@14 6 l <- source i;
kkallio@14 7
kkallio@14 8 return {Val = v,
kkallio@14 9 Last = l}
kkallio@14 10
kkallio@14 11 fun addChangeListener [t ::: Type] (_ : eq t) f pollInterval cp =
kkallio@14 12 let
kkallio@14 13 fun go () =
kkallio@14 14 sleep pollInterval;
kkallio@14 15 sample <- get cp.Val;
kkallio@14 16 lst <- get cp.Last;
kkallio@14 17 if sample = lst then
kkallio@14 18 go ()
kkallio@14 19 else
kkallio@14 20 f sample;
kkallio@14 21 set cp.Last sample;
kkallio@14 22 go ()
kkallio@14 23 in
kkallio@14 24 go ()
kkallio@14 25 end
kkallio@14 26
kkallio@14 27 fun ctl [t ::: Type] cp = cp.Val
kkallio@14 28
kkallio@14 29 fun value [t ::: Type] cp = signal (cp.Val)
kkallio@14 30