annotate demo/roundTrip.ur @ 698:9b29ce0babb8

RoundTrip demo
author Adam Chlipala <adamc@hcoop.net>
date Sun, 05 Apr 2009 11:24:55 -0400
parents
children 1a317a707d71
rev   line source
adamc@698 1 table channels : { Client : client, Channel : channel (string * int * float) }
adamc@698 2
adamc@698 3 fun writeBack v =
adamc@698 4 me <- self;
adamc@698 5 r <- oneRow (SELECT channels.Channel FROM channels WHERE channels.Client = {[me]});
adamc@698 6 send r.Channels.Channel v
adamc@698 7
adamc@698 8 fun main () =
adamc@698 9 me <- self;
adamc@698 10 ch <- channel;
adamc@698 11 dml (INSERT INTO channels (Client, Channel) VALUES ({[me]}, {[ch]}));
adamc@698 12
adamc@698 13 buf <- Buffer.create;
adamc@698 14
adamc@698 15 let
adamc@698 16 fun receiver () =
adamc@698 17 v <- recv ch;
adamc@698 18 Buffer.write buf ("(" ^ v.1 ^ ", " ^ show v.2 ^ ", " ^ show v.3 ^ ")");
adamc@698 19 receiver ()
adamc@698 20
adamc@698 21 fun sender s n f =
adamc@698 22 sleep 2000;
adamc@698 23 writeBack (s, n, f);
adamc@698 24 sender (s ^ "!") (n + 1) (f + 1.23)
adamc@698 25 in
adamc@698 26 return <xml><body onload={spawn (receiver ()); sender "" 0 0.0}>
adamc@698 27 <dyn signal={Buffer.render buf}/>
adamc@698 28 </body></xml>
adamc@698 29 end