In the documentation for mapConcurrently it says
Take into account that
async
will try to immediately spawn a thread for each element of theTraversable
, so running this on large inputs without care may lead to resource exhaustion (of memory, file descriptors, or other limited resources).
I understand the danger of using it comes from what those asyncs actually do (like each opening a file or opening network connection) rather than from the nature of async
itself? As far as I understand Haskell concurrency, threads are rather lightweight and will still map to capabilities available. What are the dangers of spawning, let’s say, 1000 such asyncs that all do rather lightweight mostly pure computations (and each has allocation limits set, so if not it will be killed). An alternative would be i.e. to create 8 worker threads that pull work from a queue until they calculate everything, but I’d like to have a definite reason to complicate the code in such a way over just mapConcurrently
.