view 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
line wrap: on
line source
con changePoller t = {Val : source t,
                      Last : source t}

fun create [t ::: Type] (_ : eq t) (i : t)  =
    v <- source i;
    l <- source i;

    return {Val = v,
            Last = l}

fun addChangeListener [t ::: Type] (_ : eq t) f pollInterval cp =
    let
        fun go () =
            sleep pollInterval;
            sample <- get cp.Val;
            lst <- get cp.Last;
            if sample = lst then
                go ()
            else
                f sample;
                set cp.Last sample;
                go ()
    in
        go ()
    end

fun ctl [t ::: Type] cp = cp.Val

fun value [t ::: Type] cp = signal (cp.Val)