Can Haskell's Control.Concurrent.Async.mapConcurrently have a limit?

后端 未结 5 512
有刺的猬
有刺的猬 2021-02-04 08:45

I\'m attempting to run multiple downloads in parallel in Haskell, which I would normally just use the Control.Concurrent.Async.mapConcurrently function for. However, doing so o

5条回答
  •  臣服心动
    2021-02-04 09:07

    You may also try the pooled-io package where you can write:

    import qualified Control.Concurrent.PooledIO.Final as Pool
    import Control.DeepSeq (NFData)
    import Data.Traversable (Traversable, traverse)
    
    mapPool ::
       (Traversable t, NFData b) =>
       Int -> (a -> IO b) -> t a -> IO (t b)
    mapPool n f = Pool.runLimited n . traverse (Pool.fork . f)
    

提交回复
热议问题