From 474fa30ad829b58eba6074e7ee14307418b07358 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Thu, 26 Mar 2009 18:26:50 -0400 Subject: Chat example working nicely, but without dead channel removal --- tests/chat.ur | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'tests/chat.ur') diff --git a/tests/chat.ur b/tests/chat.ur index 710d97d4..2d79cd00 100644 --- a/tests/chat.ur +++ b/tests/chat.ur @@ -1,10 +1,69 @@ +datatype log = End | Line of string * source log + +fun render log = + case log of + End => + | Line (line, logS) => {[line]}
+ +and renderS logS = + log <- signal logS; + return (render log) + sequence s table t : { Id : int, Title : string, Chan : option (channel string) } +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); + + newLine <- source ""; + logHead <- source End; + logTail <- source logHead; + + let + fun join () = subscribe ch + + fun onload () = + let + fun listener () = + s <- recv ch; + oldTail <- get logTail; + newTail <- source End; + set oldTail (Line (s, newTail)); + set logTail newTail; + listener () + in + join (); + listener () + end + + fun speak line = + send ch line + + fun doSpeak () = + line <- get newLine; + speak line + in + return +

{[r.T.Title]}

+ +