on 32ff950 help sign in
45 lines 845 B history raw
1{-# OPTIONS_GHC -Wall #-}
2module Reporting.Progress.Repl
3 ( create
4 )
5 where
8import Control.Concurrent (forkIO)
9import Control.Concurrent.Chan (Chan, newChan, readChan)
10import Control.Concurrent.MVar (newEmptyMVar, putMVar)
12import qualified Reporting.Error2 as Error
13import qualified Reporting.Progress as Progress
17-- CREATE
20create :: IO Progress.Reporter
21create =
22 do chan <- newChan
23 mvar <- newEmptyMVar
24 _ <- forkIO (loop chan >>= putMVar mvar)
25 return (Progress.makeReporter chan mvar)
29-- LOOP
32loop :: Chan Progress.Msg -> IO ()
33loop chan =
34 do msg <- readChan chan
35 case msg of
36 Progress.Progress _ ->
37 loop chan
39 Progress.End maybeError ->
40 case maybeError of
41 Just err ->
42 Error.toStderr err
44 Nothing ->
45 return ()