Return ThreadId with ProgressIndicator

Why?
====

It's common to return a two-tuple of `(ThreadId, a)` when performing a
forking operation to provide a handle to the thread.
This commit is contained in:
Joshua Clayton 2016-05-16 06:06:51 -04:00
parent 8c5e94c862
commit 85df4ae01f
2 changed files with 4 additions and 4 deletions

View File

@ -23,7 +23,7 @@ createSpinner =
progressWithIndicator :: (a -> IO [b]) -> ProgressIndicator -> [a] -> IO [b]
progressWithIndicator f i terms = do
printPrefix i
indicator <- start i $ length terms
(_, indicator) <- start i $ length terms
concat <$> parallel (ioOps indicator) <* stop indicator <* stopGlobalPool
where
ioOps i' = map (\t -> f t <* increment i') terms

View File

@ -11,13 +11,13 @@ import System.ProgressBar (ProgressRef, startProgress, incProgress, msg, percent
import Unused.CLI.ProgressIndicator.Types
import Unused.CLI.Util
start :: ProgressIndicator -> Int -> IO ProgressIndicator
start :: ProgressIndicator -> Int -> IO (ThreadId, ProgressIndicator)
start s@Spinner{} _ = do
tid <- forkIO $ runSpinner 0 s
return $ s { sThreadId = Just tid }
return (tid, s { sThreadId = Just tid })
start ProgressBar{} i = do
(ref, tid) <- buildProgressBar $ toInteger i
return $ ProgressBar (Just ref) (Just tid)
return (tid, ProgressBar (Just ref) (Just tid))
stop :: ProgressIndicator -> IO ()
stop ProgressBar{ pbThreadId = Just tid } = killThread tid