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: