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

后端 未结 5 516
有刺的猬
有刺的猬 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:02

    If you have actions in a list, this one has less dependencies

    import Control.Concurrent.Async (mapConcurrently)
    import Data.List.Split (chunksOf)
    
    mapConcurrentChunks :: Int -> (a -> IO b) -> [a] -> IO [b]
    mapConcurrentChunks n ioa xs = concat <$> mapM (mapConcurrently ioa) (chunksOf n xs)
    

    Edit: Just shortened a bit

提交回复
热议问题