Skip to content

Commit

Permalink
add sequenceConcurrentlyBoundedRebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundnoble committed Nov 16, 2024
1 parent a25dc26 commit 88910f0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cabal-install/src/Distribution/Client/RebuildMonad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module Distribution.Client.RebuildMonad
, findFileWithExtensionMonitored
, findFirstFileMonitored
, findFileMonitored
, sequenceConcurrentlyBoundedRebuild
) where

import Distribution.Client.Compat.Prelude
Expand All @@ -66,7 +67,7 @@ import Distribution.Client.Glob hiding (matchFileGlob)
import qualified Distribution.Client.Glob as Glob (matchFileGlob)
import Distribution.Simple.PreProcess.Types (Suffix (..))

import Distribution.Simple.Utils (debug)
import Distribution.Simple.Utils (debug, sequenceConcurrentlyBounded)

import Control.Concurrent.MVar (MVar, modifyMVar, newMVar)
import Control.Monad.Reader as Reader
Expand Down Expand Up @@ -330,3 +331,13 @@ findFileMonitored searchPath fileName =
[ path </> fileName
| path <- nub searchPath
]

-- | Run multiple 'Rebuild' actions in parallel, collecting the final
-- list of used files.
sequenceConcurrentlyBoundedRebuild :: Int -> [Rebuild a] -> Rebuild [a]
sequenceConcurrentlyBoundedRebuild n xs = do
root <- askRoot
results <- liftIO $ sequenceConcurrentlyBounded n (unRebuild root <$> xs)
for results $ \(a, files) -> do
monitorFiles files
return a

0 comments on commit 88910f0

Please sign in to comment.