module Com.Simatime.Sema
    ( 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