mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-09-11 04:45:28 +03:00
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:
parent
8c5e94c862
commit
85df4ae01f
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user