adam@10: (** Reactive view of the current time *) adam@10: adam@11: type t = { adam@11: Source : source time, (* Server time as of last tick event *) adam@11: Skew : source int, (* How many seconds do we add to the local clock to match the server clock? *) adam@11: Period : int (* How many milliseconds between ticks? *) adam@11: } adam@10: adam@10: fun create ms = adam@10: tm <- now; adam@10: t <- source tm; adam@11: sk <- source 0; adam@11: return {Source = t, Skew = sk, Period = ms} adam@10: adam@10: fun start t = adam@10: let adam@10: fun loop () = adam@10: sleep t.Period; adam@10: tm <- now; adam@11: sk <- get t.Skew; adam@11: set t.Source (addSeconds tm sk); adam@10: loop () adam@11: adam@11: fun serverTime () = now adam@10: in adam@11: spawn (server <- rpc (serverTime ()); adam@11: local <- now; adam@17: set t.Skew (diffInSeconds local server)); adam@10: spawn (loop ()) adam@10: end adam@10: adam@10: fun signal t = Basis.signal t.Source