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@682: structure Room = Broadcast(struct adamc@682: type t = string adamc@682: end) adamc@682: adamc@678: sequence s adamc@682: table t : { Id : int, Title : string, Room : Room.topic } adamc@678: adamc@679: fun chat id = adamc@682: r <- oneRow (SELECT t.Title, t.Room FROM t WHERE t.Id = {[id]}); adamc@682: ch <- Room.subscribe r.T.Room; adamc@679: adamc@679: newLine <- source ""; adamc@679: logHead <- source End; adamc@679: logTail <- source logHead; adamc@679: adamc@679: let 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: listener () adamc@679: end adamc@679: adamc@682: fun getRoom () = adamc@682: r <- oneRow (SELECT t.Room FROM t WHERE t.Id = {[id]}); adamc@682: return r.T.Room adamc@682: adamc@679: fun speak line = adamc@682: room <- getRoom (); adamc@682: Room.send room line adamc@679: adamc@679: fun doSpeak () = adamc@679: line <- get newLine; adamc@690: set newLine ""; adamc@679: speak line adamc@679: in adamc@679: return adamc@679:

{[r.T.Title]}

adamc@679: adamc@679: