2012-06-22 19:46:21 +00:00
|
|
|
{- 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.
|
2012-06-26 21:33:34 +00:00
|
|
|
- Returns the values partitioned into ones with which the action succeeded,
|
|
|
|
- and ones with which it failed. -}
|
|
|
|
inParallel :: (v -> IO ()) -> [v] -> IO ([v], [v])
|
2012-06-23 05:33:10 +00:00
|
|
|
inParallel a l = do
|
|
|
|
pids <- mapM (forkProcess . a) l
|
2012-06-22 19:46:21 +00:00
|
|
|
statuses <- mapM (getProcessStatus True False) pids
|
2012-06-26 21:33:34 +00:00
|
|
|
return $ reduce $ partition (succeeded . snd) $ zip l statuses
|
2012-06-22 19:46:21 +00:00
|
|
|
where
|
2012-06-26 21:33:34 +00:00
|
|
|
succeeded v = v == Just (Exited ExitSuccess)
|
|
|
|
reduce (x,y) = (map fst x, map fst y)
|