blob: f4a79316c7092b0700afadf53cddc12292bb5deb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
{- parallel processes
-
- Copyright 2012 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Utility.Parallel where
import Common
import System.Posix.Process
{- 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)
|