Mercurial > urweb
annotate tests/roundTrip.ur @ 1295:929981850d9d
'tryDml' works with Postgres
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Tue, 07 Sep 2010 09:06:13 -0400 |
parents | 7c6b6c3c7b79 |
children | 8a169fc0838b |
rev | line source |
---|---|
adamc@728 | 1 table channels : { Client : client, Channel : channel (string * int * float) } |
adamc@728 | 2 PRIMARY KEY Client |
adamc@728 | 3 |
adamc@728 | 4 fun writeBack v = |
adamc@728 | 5 me <- self; |
adamc@728 | 6 r <- oneRow (SELECT channels.Channel FROM channels WHERE channels.Client = {[me]}); |
adamc@728 | 7 send r.Channels.Channel v |
adamc@728 | 8 |
adamc@728 | 9 fun main () = |
adamc@728 | 10 me <- self; |
adamc@728 | 11 ch <- channel; |
adamc@728 | 12 dml (INSERT INTO channels (Client, Channel) VALUES ({[me]}, {[ch]})); |
adamc@728 | 13 |
adamc@728 | 14 buf <- Buffer.create; |
adamc@728 | 15 |
adamc@728 | 16 let |
adamc@728 | 17 fun receiverA () = |
adamc@728 | 18 v <- recv ch; |
adamc@728 | 19 Buffer.write buf ("A:(" ^ v.1 ^ ", " ^ show v.2 ^ ", " ^ show v.3 ^ ")"); |
adamc@728 | 20 receiverA () |
adamc@728 | 21 |
adamc@728 | 22 fun receiverB () = |
adamc@728 | 23 v <- recv ch; |
adamc@728 | 24 Buffer.write buf ("B:(" ^ v.1 ^ ", " ^ show v.2 ^ ", " ^ show v.3 ^ ")"); |
adamc@728 | 25 error <xml>Bail out!</xml>; |
adamc@728 | 26 receiverB () |
adamc@728 | 27 |
adamc@728 | 28 fun sender s n f = |
adamc@729 | 29 sleep 2000; |
adamc@728 | 30 writeBack (s, n, f); |
adamc@728 | 31 sender (s ^ "!") (n + 1) (f + 1.23) |
adamc@728 | 32 in |
adamc@729 | 33 return <xml><body onload={onDisconnect (alert "Server booted me"); |
adamc@729 | 34 onConnectFail (alert "Connection failed"); |
adamc@729 | 35 onServerError (fn s => alert ("Server error: " ^ s)); |
adamc@729 | 36 spawn (receiverA ()); spawn (receiverB ()); sender "" 0 0.0}> |
adamc@728 | 37 <dyn signal={Buffer.render buf}/> |
adamc@728 | 38 </body></xml> |
adamc@728 | 39 end |