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 :: (a -> IO [b]) -> ProgressIndicator -> [a] -> IO [b]
|
||||||
progressWithIndicator f i terms = do
|
progressWithIndicator f i terms = do
|
||||||
printPrefix i
|
printPrefix i
|
||||||
indicator <- start i $ length terms
|
(_, indicator) <- start i $ length terms
|
||||||
concat <$> parallel (ioOps indicator) <* stop indicator <* stopGlobalPool
|
concat <$> parallel (ioOps indicator) <* stop indicator <* stopGlobalPool
|
||||||
where
|
where
|
||||||
ioOps i' = map (\t -> f t <* increment i') terms
|
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.ProgressIndicator.Types
|
||||||
import Unused.CLI.Util
|
import Unused.CLI.Util
|
||||||
|
|
||||||
start :: ProgressIndicator -> Int -> IO ProgressIndicator
|
start :: ProgressIndicator -> Int -> IO (ThreadId, ProgressIndicator)
|
||||||
start s@Spinner{} _ = do
|
start s@Spinner{} _ = do
|
||||||
tid <- forkIO $ runSpinner 0 s
|
tid <- forkIO $ runSpinner 0 s
|
||||||
return $ s { sThreadId = Just tid }
|
return (tid, s { sThreadId = Just tid })
|
||||||
start ProgressBar{} i = do
|
start ProgressBar{} i = do
|
||||||
(ref, tid) <- buildProgressBar $ toInteger i
|
(ref, tid) <- buildProgressBar $ toInteger i
|
||||||
return $ ProgressBar (Just ref) (Just tid)
|
return (tid, ProgressBar (Just ref) (Just tid))
|
||||||
|
|
||||||
stop :: ProgressIndicator -> IO ()
|
stop :: ProgressIndicator -> IO ()
|
||||||
stop ProgressBar{ pbThreadId = Just tid } = killThread tid
|
stop ProgressBar{ pbThreadId = Just tid } = killThread tid
|
||||||
|
Loading…
Reference in New Issue
Block a user