git-annex/Utility/Parallel.hs

21 lines
543 B
Haskell
Raw Normal View History

{- parallel processes
-
- Copyright 2012 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Utility.Parallel where
import Common
{- Runs an action in parallel with a set of values.
- Returns values that caused the action to fail. -}
inParallel :: (v -> IO ()) -> [v] -> IO [v]
2012-06-23 05:33:10 +00:00
inParallel a l = do
pids <- mapM (forkProcess . a) l
statuses <- mapM (getProcessStatus True False) pids
2012-06-23 05:33:10 +00:00
return $ map fst $ filter (failed . snd) $ zip l statuses
where
2012-06-23 05:33:10 +00:00
failed v = v /= Just (Exited ExitSuccess)