pooledMapConcurrentlyN
only works in simple situations, so QSem
is definitely something that should be in a Haskeller’s engineering toolkit.
For instance, I wanted my tool to respect a -j
param when generating an import graph pruned to a specific module. The algorithm is
- Parse imports from the file we are pruning too.
- Recursively parse all its imports.
- Repeat until we hit the leaves.
I want a stable -j
across that concurrency. Using pooledMapConcurrentlyN
naively to do step 2 would violate -j
since each recursive call would also call it. So a QSem
is a better fit. (Code here)
And I wouldn’t really consider it reinventing the wheel. Programming with semaphores is a pretty fundamental engineering skill that every programmer who does concurrency should be able to do