adamc@679: datatype log = End | Line of string * source log
adamc@679:
adamc@679: fun render log =
adamc@679: case log of
adamc@679: End =>
adamc@679: | Line (line, logS) => {[line]}
adamc@679:
adamc@679: and renderS logS =
adamc@679: log <- signal logS;
adamc@679: return (render log)
adamc@679:
adamc@678: sequence s
adamc@678: table t : { Id : int, Title : string, Chan : option (channel string) }
adamc@678:
adamc@679: fun chat id =
adamc@679: r <- oneRow (SELECT t.Title, t.Chan FROM t WHERE t.Id = {[id]});
adamc@679: ch <- (case r.T.Chan of
adamc@679: None => (ch <- channel;
adamc@679: dml (UPDATE t SET Chan = {[Some ch]} WHERE Id = {[id]});
adamc@679: return ch)
adamc@679: | Some ch => return ch);
adamc@679:
adamc@679: newLine <- source "";
adamc@679: logHead <- source End;
adamc@679: logTail <- source logHead;
adamc@679:
adamc@679: let
adamc@679: fun join () = subscribe ch
adamc@679:
adamc@679: fun onload () =
adamc@679: let
adamc@679: fun listener () =
adamc@679: s <- recv ch;
adamc@679: oldTail <- get logTail;
adamc@679: newTail <- source End;
adamc@679: set oldTail (Line (s, newTail));
adamc@679: set logTail newTail;
adamc@679: listener ()
adamc@679: in
adamc@679: join ();
adamc@679: listener ()
adamc@679: end
adamc@679:
adamc@679: fun speak line =
adamc@679: send ch line
adamc@679:
adamc@679: fun doSpeak () =
adamc@679: line <- get newLine;
adamc@679: speak line
adamc@679: in
adamc@679: return
adamc@679: {[r.T.Title]}
adamc@679:
adamc@679:
adamc@679:
adamc@679: Messages
adamc@679:
adamc@679:
adamc@679:
adamc@679:
adamc@679: end
adamc@679:
adamc@678: fun list () =
adamc@678: queryX (SELECT * FROM t)
adamc@678: (fn r =>
adamc@679: {[r.T.Id]} {[r.T.Title]}
adamc@678: [delete]
adamc@678: )
adamc@678:
adamc@678: and delete id =
adamc@678: dml (DELETE FROM t WHERE Id = {[id]});
adamc@678: main ()
adamc@678:
adamc@678: and main () : transaction page =
adamc@678: let
adamc@678: fun create r =
adamc@678: id <- nextval s;
adamc@678: dml (INSERT INTO t (Id, Title, Chan) VALUES ({[id]}, {[r.Title]}, NULL));
adamc@678: main ()
adamc@678: in
adamc@678: ls <- list ();
adamc@678: return
adamc@678:
adamc@678: ID Title
adamc@678: {ls}
adamc@678:
adamc@678:
adamc@678: New Channel
adamc@678:
adamc@678:
adamc@678:
adamc@678: end