adam@0: type t = {Milliseconds : int, adam@0: Action : source (string -> transaction {}), adam@0: Timer : source (option Timer.t), adam@0: Text : source string} adam@0: adam@0: fun create n = adam@0: s <- source ""; adam@0: tmO <- source None; adam@0: f <- source (fn _ => return ()); adam@0: adam@0: return {Milliseconds = n, Action = f, Timer = tmO, Text = s} adam@0: adam@0: fun setAction r v = set r.Action v adam@0: adam@0: fun tickle r = adam@0: last <- get r.Timer; adam@0: (case last of adam@0: None => return () adam@0: | Some tm => Timer.cancel tm); adam@0: tm <- Timer.create {Milliseconds = r.Milliseconds, adam@0: Action = (set r.Timer None; adam@0: s <- get r.Text; adam@0: f <- get r.Action; adam@0: f s)}; adam@0: set r.Timer (Some tm) adam@0: adam@0: fun render r = adam@0: tickle r}/> adam@0: adam@0: adam@0: fun clear r = (set r.Text ""; adam@0: tm <- get r.Timer; adam@0: (case tm of adam@0: None => return () adam@0: | Some tm => Timer.cancel tm); adam@0: set r.Timer None) adam@0: adam@0: fun trigger r = adam@0: last <- get r.Timer; adam@0: (case last of adam@0: None => return () adam@0: | Some tm => Timer.cancel tm); adam@0: set r.Timer None; adam@0: s <- get r.Text; adam@0: f <- get r.Action; adam@0: f s