diff options
Diffstat (limited to 'Utility/Parallel.hs')
-rw-r--r-- | Utility/Parallel.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Utility/Parallel.hs b/Utility/Parallel.hs new file mode 100644 index 000000000..a512a6d30 --- /dev/null +++ b/Utility/Parallel.hs @@ -0,0 +1,20 @@ +{- 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] +inParallel a v = do + pids <- mapM (forkProcess . a) v + statuses <- mapM (getProcessStatus True False) pids + return $ map fst $ filter failed $ zip v statuses + where + failed (_, status) = status /= Just (Exited ExitSuccess) |