summaryrefslogtreecommitdiff
path: root/tests/chat.ur
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-03-29 11:37:29 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-03-29 11:37:29 -0400
commit843fcc973f4cf7b149d4f57732fb66f812115320 (patch)
treebae33dd5ebd8393e6dd1b30f7d1a2b75241c9956 /tests/chat.ur
parent9f3c3a0215d3f23c8e51fa4824d21dfeaa08ede0 (diff)
Redo channels, making them single-client
Diffstat (limited to 'tests/chat.ur')
-rw-r--r--tests/chat.ur36
1 files changed, 15 insertions, 21 deletions
diff --git a/tests/chat.ur b/tests/chat.ur
index b982836d..8763a190 100644
--- a/tests/chat.ur
+++ b/tests/chat.ur
@@ -9,32 +9,22 @@ and renderS logS =
log <- signal logS;
return (render log)
+structure Room = Broadcast(struct
+ type t = string
+ end)
+
sequence s
-table t : { Id : int, Title : string, Chan : option (channel string) }
+table t : { Id : int, Title : string, Room : Room.topic }
fun chat id =
- r <- oneRow (SELECT t.Title, t.Chan FROM t WHERE t.Id = {[id]});
- ch <- (case r.T.Chan of
- None => (ch <- channel;
- dml (UPDATE t SET Chan = {[Some ch]} WHERE Id = {[id]});
- return ch)
- | Some ch => return ch);
+ r <- oneRow (SELECT t.Title, t.Room FROM t WHERE t.Id = {[id]});
+ ch <- Room.subscribe r.T.Room;
newLine <- source "";
logHead <- source End;
logTail <- source logHead;
let
- fun getCh () =
- r <- oneRow (SELECT t.Chan FROM t WHERE t.Id = {[id]});
- case r.T.Chan of
- None => error <xml>Channel disappeared</xml>
- | Some ch => return ch
-
- fun join () =
- ch <- getCh ();
- subscribe ch
-
fun onload () =
let
fun listener () =
@@ -45,13 +35,16 @@ fun chat id =
set logTail newTail;
listener ()
in
- join ();
listener ()
end
+ fun getRoom () =
+ r <- oneRow (SELECT t.Room FROM t WHERE t.Id = {[id]});
+ return r.T.Room
+
fun speak line =
- ch <- getCh ();
- send ch line
+ room <- getRoom ();
+ Room.send room line
fun doSpeak () =
line <- get newLine;
@@ -84,7 +77,8 @@ and main () : transaction page =
let
fun create r =
id <- nextval s;
- dml (INSERT INTO t (Id, Title, Chan) VALUES ({[id]}, {[r.Title]}, NULL));
+ room <- Room.create;
+ dml (INSERT INTO t (Id, Title, Room) VALUES ({[id]}, {[r.Title]}, {[room]}));
main ()
in
ls <- list ();