diff options
Diffstat (limited to 'Utility/Parallel.hs')
-rw-r--r-- | Utility/Parallel.hs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Utility/Parallel.hs b/Utility/Parallel.hs new file mode 100644 index 000000000..9df95ab2b --- /dev/null +++ b/Utility/Parallel.hs @@ -0,0 +1,22 @@ +{- 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 the values partitioned into ones with which the action succeeded, + - and ones with which it failed. -} +inParallel :: (v -> IO ()) -> [v] -> IO ([v], [v]) +inParallel a l = do + pids <- mapM (forkProcess . a) l + statuses <- mapM (getProcessStatus True False) pids + return $ reduce $ partition (succeeded . snd) $ zip l statuses + where + succeeded v = v == Just (Exited ExitSuccess) + reduce (x,y) = (map fst x, map fst y) |