Mercurial > urweb
annotate tests/roundTrip.ur @ 728:2197f0e24a9f
Avoid thread death via message receive
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 16 Apr 2009 13:00:40 -0400 |
parents | |
children | 7c6b6c3c7b79 |
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@728 | 29 sleep 9; |
adamc@728 | 30 writeBack (s, n, f); |
adamc@728 | 31 sender (s ^ "!") (n + 1) (f + 1.23) |
adamc@728 | 32 in |
adamc@728 | 33 return <xml><body onload={spawn (receiverA ()); spawn (receiverB ()); sender "" 0 0.0}> |
adamc@728 | 34 <dyn signal={Buffer.render buf}/> |
adamc@728 | 35 </body></xml> |
adamc@728 | 36 end |