summaryrefslogtreecommitdiff
path: root/lore/Control/Concurrent/Sima.hs
blob: b69c0bb3967b1faa1fed0242650b9df7333c0467 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
module Control.Concurrent.Sima
    ( mapPool
    )
where

import qualified Control.Concurrent.MSem as Sem

-- | Simaphore-based throttled 'mapConcurrently'.
mapPool :: Traversable t => Int -> (a -> IO b) -> t a -> IO (t b)
mapPool n f xs = do
    sima <- Sem.new n
    mapConcurrently (Sem.with sima . f) xs