summaryrefslogtreecommitdiff
path: root/com/simatime/sema.hs
diff options
context:
space:
mode:
Diffstat (limited to 'com/simatime/sema.hs')
-rw-r--r--com/simatime/sema.hs12
1 files changed, 12 insertions, 0 deletions
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