comparison tests/spawn.ur @ 694:7ea0df9e56b6

spawn
author Adam Chlipala <adamc@hcoop.net>
date Sat, 04 Apr 2009 14:55:36 -0400
parents
children
comparison
equal deleted inserted replaced
693:655bcc9b77e0 694:7ea0df9e56b6
1 table t : {A : int, Ch : channel string}
2
3 fun listener n ch =
4 s <- recv ch;
5 alert (show n ^ ": " ^ s);
6 listener n ch
7
8 fun speak id msg =
9 r <- oneRow (SELECT t.Ch FROM t WHERE t.A = {[id]});
10 send r.T.Ch msg
11
12 fun main () : transaction page =
13 ch1 <- channel;
14 dml (INSERT INTO t (A, Ch) VALUES (1, {[ch1]}));
15 ch2 <- channel;
16 dml (INSERT INTO t (A, Ch) VALUES (2, {[ch2]}));
17
18 s1 <- source "";
19 s2 <- source "";
20
21 return <xml><body onload={spawn (listener 1 ch1); spawn (listener 2 ch2)}>
22 1: <ctextbox source={s1}/><button onclick={msg <- get s1; speak 1 msg}/><br/>
23 2: <ctextbox source={s2}/><button onclick={msg <- get s2; speak 2 msg}/>
24 </body></xml>