summaryrefslogtreecommitdiff
path: root/Control/Concurrent/Sema.hs
blob: 21d47095c0b05478c0e188bdaa3bfde4617348d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-- | A stupid Semaphore utility thing
module Control.Concurrent.Sema
  ( mapPool,
  )
where

import Alpha
import Control.Concurrent.Async (mapConcurrently)
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