summaryrefslogtreecommitdiffhomepage
path: root/Role/Downloader.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-24 15:24:52 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-24 16:03:46 -0400
commit9a8d3bc531647d8b96e66e6daabf2176a1df4afb (patch)
tree5f198a02e59fbec20b38ad347db37cad97b3ed0d /Role/Downloader.hs
parent7b2bcfab392d387b89c3c251f0c9a8b9c0203aa8 (diff)
downloaddebug-me-9a8d3bc531647d8b96e66e6daabf2176a1df4afb.tar.gz
switch to TMChans so they can be closed when a connection is Done
Diffstat (limited to 'Role/Downloader.hs')
-rw-r--r--Role/Downloader.hs18
1 files changed, 11 insertions, 7 deletions
diff --git a/Role/Downloader.hs b/Role/Downloader.hs
index d327c8c..55d7b63 100644
--- a/Role/Downloader.hs
+++ b/Role/Downloader.hs
@@ -6,12 +6,13 @@ import CmdLine
import SessionID
import Control.Concurrent.STM
+import Control.Concurrent.STM.TMChan
import Role.Developer (run', processSessionStart, getUserMessage, Output(..))
run :: DownloadOpts -> IO ()
run = run' downloader . downloadUrl
-downloader :: TChan (Message Entered) -> TChan (Message Seen) -> SessionID -> IO ()
+downloader :: TMChan (Message Entered) -> TMChan (Message Seen) -> SessionID -> IO ()
downloader _ichan ochan sid = do
let logfile = sessionLogFile "." sid
putStrLn $ "Starting download to " ++ logfile
@@ -21,9 +22,12 @@ downloader _ichan ochan sid = do
go logger st
where
go logger st = do
- (o, msg) <- atomically $ getUserMessage ochan st
- _ <- logger $ User msg
- case o of
- ProtocolError e -> error ("Protocol error: " ++ e)
- _ -> return ()
- go logger st
+ v <- atomically $ getUserMessage ochan st
+ case v of
+ Nothing -> return ()
+ Just (o, msg) -> do
+ _ <- logger $ User msg
+ case o of
+ ProtocolError e -> error ("Protocol error: " ++ e)
+ _ -> return ()
+ go logger st