From c790672cc244ac4caba1bda3572829a6c6862891 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sun, 27 Oct 2019 09:48:52 -0700 Subject: move everything to namespace directories --- com/simatime/sema.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 com/simatime/sema.hs (limited to 'com/simatime/sema.hs') diff --git a/com/simatime/sema.hs b/com/simatime/sema.hs new file mode 100644 index 0000000..f0f75da --- /dev/null +++ b/com/simatime/sema.hs @@ -0,0 +1,12 @@ +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 -- cgit v1.2.3