Hoogle Search
Within LTS Haskell 24.34 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
pooledMapConcurrently :: (MonadUnliftIO m, Traversable t) => (a -> m b) -> t a -> m (t b)unliftio UnliftIO.Async Similar to pooledMapConcurrentlyN but with number of threads set from getNumCapabilities. Usually this is useful for CPU bound tasks.
pooledMapConcurrentlyN :: (MonadUnliftIO m, Traversable t) => Int -> (a -> m b) -> t a -> m (t b)unliftio UnliftIO.Async Like mapConcurrently from async, but instead of one thread per element, it does pooling from a set of threads. This is useful in scenarios where resource consumption is bounded and for use cases where too many concurrent tasks aren't allowed.
Example usage
import Say action :: Int -> IO Int action n = do tid <- myThreadId sayString $ show tid threadDelay (2 * 10^6) -- 2 seconds return n main :: IO () main = do yx <- pooledMapConcurrentlyN 5 (\x -> action x) [1..5] print yx
On executing you can see that five threads have been spawned:$ ./pool ThreadId 36 ThreadId 38 ThreadId 40 ThreadId 42 ThreadId 44 [1,2,3,4,5]
Let's modify the above program such that there are less threads than the number of items in the list:import Say action :: Int -> IO Int action n = do tid <- myThreadId sayString $ show tid threadDelay (2 * 10^6) -- 2 seconds return n main :: IO () main = do yx <- pooledMapConcurrentlyN 3 (\x -> action x) [1..5] print yx
On executing you can see that only three threads are active totally:$ ./pool ThreadId 35 ThreadId 37 ThreadId 39 ThreadId 35 ThreadId 39 [1,2,3,4,5]
pooledMapConcurrentlyN_ :: (MonadUnliftIO m, Foldable f) => Int -> (a -> m b) -> f a -> m ()unliftio UnliftIO.Async Like pooledMapConcurrentlyN but with the return value discarded.
pooledMapConcurrently_ :: (MonadUnliftIO m, Foldable f) => (a -> m b) -> f a -> m ()unliftio UnliftIO.Async Like pooledMapConcurrently but with the return value discarded.
pooledMapConcurrently :: (MonadUnliftIO m, Traversable t) => (a -> m b) -> t a -> m (t b)unliftio UnliftIO.Internals.Async Similar to pooledMapConcurrentlyN but with number of threads set from getNumCapabilities. Usually this is useful for CPU bound tasks.
pooledMapConcurrentlyIO :: Traversable t => Int -> (a -> IO b) -> t a -> IO (t b)unliftio UnliftIO.Internals.Async No documentation available.
pooledMapConcurrentlyIO' :: Traversable t => Int -> (a -> IO b) -> t a -> IO (t b)unliftio UnliftIO.Internals.Async No documentation available.
pooledMapConcurrentlyIO_ :: Foldable t => Int -> (a -> IO b) -> t a -> IO ()unliftio UnliftIO.Internals.Async No documentation available.
pooledMapConcurrentlyIO_' :: Foldable t => Int -> (a -> IO ()) -> t a -> IO ()unliftio UnliftIO.Internals.Async No documentation available.
pooledMapConcurrentlyN :: (MonadUnliftIO m, Traversable t) => Int -> (a -> m b) -> t a -> m (t b)unliftio UnliftIO.Internals.Async Like mapConcurrently from async, but instead of one thread per element, it does pooling from a set of threads. This is useful in scenarios where resource consumption is bounded and for use cases where too many concurrent tasks aren't allowed.
Example usage
import Say action :: Int -> IO Int action n = do tid <- myThreadId sayString $ show tid threadDelay (2 * 10^6) -- 2 seconds return n main :: IO () main = do yx <- pooledMapConcurrentlyN 5 (\x -> action x) [1..5] print yx
On executing you can see that five threads have been spawned:$ ./pool ThreadId 36 ThreadId 38 ThreadId 40 ThreadId 42 ThreadId 44 [1,2,3,4,5]
Let's modify the above program such that there are less threads than the number of items in the list:import Say action :: Int -> IO Int action n = do tid <- myThreadId sayString $ show tid threadDelay (2 * 10^6) -- 2 seconds return n main :: IO () main = do yx <- pooledMapConcurrentlyN 3 (\x -> action x) [1..5] print yx
On executing you can see that only three threads are active totally:$ ./pool ThreadId 35 ThreadId 37 ThreadId 39 ThreadId 35 ThreadId 39 [1,2,3,4,5]