From 9a8d3bc531647d8b96e66e6daabf2176a1df4afb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 24 Apr 2017 15:24:52 -0400 Subject: switch to TMChans so they can be closed when a connection is Done --- Role/Watcher.hs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'Role/Watcher.hs') diff --git a/Role/Watcher.hs b/Role/Watcher.hs index 620733c..6ed1a6b 100644 --- a/Role/Watcher.hs +++ b/Role/Watcher.hs @@ -7,17 +7,21 @@ import CmdLine import SessionID import Control.Concurrent.STM +import Control.Concurrent.STM.TMChan import Role.Developer (run', processSessionStart, getUserMessage, emitOutput) run :: WatchOpts -> IO () run = run' watcher . watchUrl -watcher :: TChan (Message Entered) -> TChan (Message Seen) -> SessionID -> IO () +watcher :: TMChan (Message Entered) -> TMChan (Message Seen) -> SessionID -> IO () watcher _ichan ochan _ = inRawMode $ do st <- processSessionStart ochan nullLogger go st where go st = do - (o, _msg) <- atomically $ getUserMessage ochan st - emitOutput o - go st + v <- atomically $ getUserMessage ochan st + case v of + Nothing -> return () + Just (o, _msg) -> do + emitOutput o + go st -- cgit v1.2.3